Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


#define assert(cond) if(!(cond)) \

(fprintf(stderr, "assertion failed: %s, file %s,
line %d \n",#cond,\

__FILE__,__LINE__), abort())

void main()

{

int i = 10;

if(i==0)

assert(i < 100);

else

printf("This statement becomes else for if in
assert macro");

}



#define assert(cond) if(!(cond)) \ (fprintf(stderr, "assertion failed: %s, file %s, ..

Answer / susie

Answer :

No output

Explanation:

The else part in which the printf is there becomes the else
for if in the assert macro. Hence nothing is printed.

The solution is to use conditional operator instead of
if statement,

#define assert(cond) ((cond)?(0): (fprintf (stderr,
"assertion failed: \ %s, file %s, line %d \n",#cond,
__FILE__,__LINE__), abort()))

Note:

However this problem of “matching with nearest else” cannot
be solved by the usual method of placing the if statement
inside a block like this,

#define assert(cond) { \

if(!(cond)) \

(fprintf(stderr, "assertion failed: %s, file %s,
line %d \n",#cond,\

__FILE__,__LINE__), abort()) \

}

Is This Answer Correct ?    5 Yes 0 No

Post New Answer

More C Code Interview Questions

abcdedcba abc cba ab ba a a

2 Answers  


Give a very good method to count the number of ones in a 32 bit number. (caution: looping through testing each bit is not a solution)

7 Answers   Microsoft,


main(){ int a= 0;int b = 20;char x =1;char y =10; if(a,b,x,y) printf("hello"); }

1 Answers   TCS,


Find the largest number in a binary tree

7 Answers   Infosys,


Write a program to print a square of size 5 by using the character S.

6 Answers   Microsoft,


Is it possible to type a name in command line without ant quotes?

1 Answers   Excel, Infosys,


What is your nationality?

1 Answers   GoDB Tech,


main() { int a=10,*j; void *k; j=k=&a; j++; k++; printf("\n %u %u ",j,k); }

1 Answers  


Is it possible to print a name without using commas, double quotes,semi-colons?

7 Answers  


void main() { int *i = 0x400; // i points to the address 400 *i = 0; // set the value of memory location pointed by i; }

2 Answers  


main() { char * strA; char * strB = I am OK; memcpy( strA, strB, 6); } a. Runtime error. b. I am OK c. Compile error d. I am O

4 Answers   HCL,


code of a program in c language that ask a number and print its decremented and incremented number.. sample output: input number : 3 321123

1 Answers   HCL,


Categories