What will be output if you will compile and execute the following c code?
#include
#define x 5+2
int main(){
int i;
i=x*x*x;
printf("%d",i);
return 0;
}
27
343
233
Compiler Error
A. 27
As we know #define is token pasting preprocessor it only paste the value of micro constant in the program before the actual compilation start. If you will see intermediate file you will find:
test.c 1:
test.c 2: void main(){
test.c 3: int i;
test.c 4: i=5+2*5+2*5+2;
test.c 5: printf("%d",i);
test.c 6: }
test.c 7:
You can absorb #define only pastes the 5+2 in place of x in program. So, i=5+2*5+2*5+2
=5+10+10+2
=27
to go to the next iteration in a loop
come out of a loop
exit and return to the main function
restarts iterations from beginning of loop
main()
{
xyz: goto abc;
printf("Hello");
abc: printf("World");
goto xyz;
}
Infinite loop
Hello World
World Hello
Compilation error
string.h
strings.h
text.h
strcmp.h
True
False
pointers to strings
string to pointer
both
the logical operator && cannot be used in a test condition
the while loop is an exit-condition loop
the test condition is always true
the test condition is always false
An Editor
A compiler
An operating system
None of the above
void main()
{
int a = 0;
while (a<=50) for(;;) if(++a % 50==0) break;
printf("a = %d", a);
}
a = 100
a = 50
compilation error
runtime error
void main()
{
int z, a = 5, b = 3; z = a * 2 + 26 % 3;
printf("%d", z); }
10
0
12
None of the above
void main()
{
int a = 1, b=2;
int *ip;
ip=&a;
b=*ip;
printf("%d", b);
}
2
1
100
0
True
False
True
False
The smallest individual units of c program
The basic element recognized by the compiler
The largest individual units of program
A & B Both
True
False
.
?
;
none of the above
True
False
delete
concatenate
compare
none of the above
True
False
0
NULL
1
none of the above
True
False
void main()
{
int a = 20;
printf("%d\t%d
", ++a, a);
}
21 21
20 21
21 20
20 20
True
False
float a =123.56;
char ch ='T' * 'A';
char ch ='T' *20;
3 +a = b;
#if
#elseif
#undef
#pragma
4
2
8
10
Sequential
Random
Sequential and Random
None of the above
do-while
if-else
goto
for
35
45
55
40
True
False
int f(int a, int b);
void main()
{
int a = 12, b=154;
printf("%d", f(a, b));
}
int f(int a, int b)
{
if (a<b) return(f(b, a));
if(b==0) return(a);
return (f(b, a % b));
}
2
1
Compilation error
Runtime error