#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");
}
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 |
Give a one-line C expression to test whether a number is a power of 2.
main() { int i=0; for(;i++;printf("%d",i)) ; printf("%d",i); }
Design an implement of the inputs functions for event mode
main() { char p[ ]="%d\n"; p[1] = 'c'; printf(p,65); }
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"
void main() { int *i = 0x400; // i points to the address 400 *i = 0; // set the value of memory location pointed by i; }
main() { int *ptr=(int*)malloc(sizeof(int)); *ptr=4; printf("%d",(*ptr)+++*ptr++); }
#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); }
void main() { int i=5; printf("%d",i++ + ++i); }
main() { char *p = “ayqm”; char c; c = ++*p++; printf(“%c”,c); }
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; } }