#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

void main() { void *v; int integer=2; int *i=&integer; v=i; printf("%d",(int*)*v); }

1 Answers   Honeywell,


C program to print magic square of order n where n > 3 and n is odd

2 Answers   Accenture,


#include"math.h" void main() { printf("Hi everybody"); } if <stdio.h> will be included then this program will must compile, but as we know that when we include a header file in "" then any system defined function find its defination from all the directrives. So is this code of segment will compile? If no then why?

2 Answers  


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,


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,






You are given any character string. Find the number of sets of vowels that come in the order of aeiou in the given string. For eg., let the given string be DIPLOMATIC. The answer returned must be "The number of sets is 2" and "The sets are "IO and AI". Vowels that form a singleton set must be neglected. Try to post the program executable in gcc or g++ or in java.

3 Answers  


Ramesh’s basic salary is input through the keyboard. His dearness allowance is 40% of basic salary, and house rent allowance is 20% of basic salary. Write a program to calculate his gross salary.

1 Answers  


how to check whether a linked list is circular.

11 Answers   Microsoft,


Write a procedure to implement highlight as a blinking operation

2 Answers  


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

1 Answers   TCS,


struct Foo { char *pName; }; main() { struct Foo *obj = malloc(sizeof(struct Foo)); clrscr(); strcpy(obj->pName,"Your Name"); printf("%s", obj->pName); } a. Your Name b. compile error c. Name d. Runtime error

3 Answers   HCL,


WAP to display 1,2,3,4,5........N

2 Answers  


Categories