top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

C:Can we use Semicolon in #define ?

+2 votes
213 views

I was in the impression that it would not but following code does not give any warning.

 #define sc ;

Any explanation?

posted Dec 12, 2015 by anonymous

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

2 Answers

0 votes

Sometime by mistake I did the same the thing but I didn't face any issue because I used the macro in one assignment statement.
For example :

#define A 10;

if you write

int val = A; /* There is no problem */

if (A == 10) /* Here compiler will generate syntax error */ 
{

}
answer Dec 12, 2015 by Harshita
0 votes

#define indicates for the macro,when in the program any variable has fix value in whole program then we use macro.

Syntax- #define variable_name value

EX:-

#include<stdio.h>
#define pi 3.14
int main()
{
  int r;
  printf("enter the radius of circle: ");
  scanf("%d",&r);
  printf("area of circle is=%f ",pi*r*r);
}

Now coming to your problem when we have the #define sc ; then sc is replaced with semicolon, u can actually use sc in the whole program in place of semicolon and it will work, pre-processor is executed prior to compilation so when compiler receives the program it has all sc replaced with semicolon.

answer Dec 13, 2015 by Shishir Chaudhary
Similar Questions
0 votes

Lot of confusion and lot of scattered info, can someone help me by providing to the point response.

–1 vote
while(i<10);
{
  i++;
  printf("%d,\n", i);
}

Loop does not run for 10 iterations, what is the error?

...