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

Give a one-line C expression to test whether a number is a power of 2.

10 Answers   Microsoft,


main() { int i=0; for(;i++;printf("%d",i)) ; printf("%d",i); }

1 Answers   Zoho,


Design an implement of the inputs functions for event mode

0 Answers   Wipro,


main() { char p[ ]="%d\n"; p[1] = 'c'; printf(p,65); }

2 Answers  


pls anyone can help me to write a code to print the values in words for any value.Example:1034 to print as "one thousand and thirty four only"

2 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() { int *ptr=(int*)malloc(sizeof(int)); *ptr=4; printf("%d",(*ptr)+++*ptr++); }

3 Answers   GNITC,


#include<stdio.h> main() { struct xx { int x=3; char name[]="hello"; }; struct xx *s=malloc(sizeof(struct xx)); printf("%d",s->x); printf("%s",s->name); }

1 Answers   TCS,


void main() { int i=5; printf("%d",i++ + ++i); }

3 Answers  


main() { char *p = “ayqm”; char c; c = ++*p++; printf(“%c”,c); }

1 Answers  


Write a program using one dimensional array to assign values and then display it on the screen. Use the formula a[i]=i*10 to assign value to an element.

1 Answers   Samar State University,


void main() { while(1){ if(printf("%d",printf("%d"))) break; else continue; } }

1 Answers  


Categories