1.#include int main(){ int a=0; #if (a==0) printf(\"Equal\"); #else if printf(\"
ID: 3538143 • Letter: 1
Question
1.#include int main(){ int a=0; #if (a==0) printf("Equal"); #else if printf("Not equal"); #endif return 0; } E (A) Equal (B) Not equal (C) Null (D) Garbage (E) Compilation error 2.What will be output if you will execute following c code? #include int main(){ for(;NULL;) printf("cquestionbank"); return 0; }C (A) c (B) bank (C) cquestionbank (D) Infinite loop (E) Compilation error 3.What will be output if you will execute following c code? #include int main(){ int x=25; if(!!x) printf("%d",!x); else printf("%d",x); return 0; }A (A) 0 (B) 25 (C) 1 (D) -1 (E) 2 4.What will be output if you will execute following c code? #include int main(){ float a=0.5, b=0.9; if(a&&b>0.9) printf("Sachin"); else printf("Rahul"); return 0; }B (A) Sachin (B) Rahul (C) null (D) Run time error (E) Compilation error 5.What will be output if you will execute following c code? C #include int main(){ int x=5, y=10; if(!(!x) && x) printf("%d",x); else printf("%d",y); return 0 ; } (A) 1 (B) 0 (C)5 (D) 10 (E) Compilation error 6.What will be output if you will execute following c code? #include int main(){ char ch=321; printf("%d %c",ch,ch); return 0 ; } B (A) 321 # (B) 65 A (C) 321 ! (D) 66 B (E) Compilation error 7.What will be output if you will execute following c code? #include int main(){ int a,b; a = -3- -3; b = -3 - - (-3 ); printf("%d %d",a,b); return 0 ; }D (A) 0 0 (B) 0 -3 (C) -3 0 (D) 0 -6 (E) Compilation error 8.What will be output if you will execute following c code? #include int main(){ int x; x= -2 + 11 - 7 * 9 % 6 / 12; printf("%d",x); return 0 ; } D (A) 6 (B) 7 (C) 8 (D) 9 (E) Compilation error 9.What will be output if you will execute following c code? #include int main(){ int x=3, y=4, z=4; printf("%d", (z>=y>=x?100:200)); return 0 ; } B (A) 100 (B) 200 (C) 0 (D) 1 (E) Compilation error 10.What will be output if you will execute following c code? #include int main(){ int a=30, b=40, x; x=(a!=10) && (b=50); printf("%d",x); return 0 ; }A (A) 1 (B)2 (C)3 (D) 4 (E) Compilation errorExplanation / Answer
1)
Syntax of conditional preprocessor directive (if) is:
#if <Constant expression>
#else
#endif
In this code (a==0) is not constant expression. A constant expression mean expression doesn%u2019t contain any variables.
Note: const int a; Here a is also variable
2)
Here NULL is micro constantan. Value of this symbolic constant is 0 or 0L as defined stdio.h:
#ifndef NULL
# if defined(__TINY__) || defined(__SMALL__) || defined(__MEDIUM__)
# define NULL 0
# else
# define NULL 0L
# endif
#endif
So corresponding intermediate file of above code will be:
int main(){
for(;0;)
printf("cquestionbank");
return 0;
}
As you know in c :
0: Means false
Non- zero: True
So for loop should not execute any time because intitial condtion is false. But it is bug of turbo c compiler. Loop will execute one time and it will print : cquestionbank
3.
! is negation operator.
!x = 0 if x is non-zero number.
!x = 1 if x is equal to zero.
So,
!!x
=! (! x)
=! (! 25)
=! (0)
=1
As we know in c:
Zero: It represents false.
Non-zero: It represents false.
if (1) means condition is true hence if part will execute.
!x =! 1 = 0
Hence printf statement will print zero in the console window.
4)
Consider on the expression:
a && b > 0.9
As we know > operator enjoy higher precedence than && operator.
So expression will be
a && (b > 0.9)
=0.5 && (0.9 > 0.9)
Properties of > (Greater than operator)
a > b returns 1 if a is greater than b.
a > b return 0 if a is less than or equal to b.
So our expression became:
= 0.5 && 0
In c zero represents false and non-zero represents true.
= true && false
= false
= 0
So, if (0) means condition is false. Hence else part will execute.
5)
Consider on expression:
! (! x) && x
=! (! 5) && 5
=! 0 && 5
=1 && 5
=1
So, if condition is true.
6)
Number 321 is beyond the range of char variable ch. So ch will store corresponding cyclic value as
Equivalent cyclic value of 321 = 321 % 128 = 65
65 is ASCII value of character 'A'
7)
Operator in c has two forms:
- : Unary minus operator (It requires one operand)
- : Binary minus operator (It requires two operands)
Note: Unary minus operator has higher precedence than binary minus operator.
8)
Consider on the expression
x = -2 + 11 - 7 * 9 % 6 / 12
There are seven different type of operator in the above expression:
Operator
Precedence
Associative
-
1
Right to left
* , % , /
2
Left to right
- , +
3
Left to right
=
4
Right to left
First of all unary minus will perform the operation
x = (-2) + 11 - 7 * 9 % 6 / 12
Now multiplication operator will perform the operation
x = (-2) + 11 - (7 * 9) % 6 / 12
x = (-2) + 11 - 63 % 6 / 12
After this modular division operator will perform operation:
x = (-2) + 11 - (63 % 6) / 12
x = (-2) + 11 - 3 / 12
After this division will perform the operation:
x = (-2) + 11 - (3 / 12)
x = (-2) + 11 - 0
Now binary plus operator will perform the operation:
x = ((-2) + 11) - 0
x = 9 - 0
Now binary minus operator will perform the operation:
x = 9
At the end assignment operator will perform the operation and it will assign 9 to variable x.
9)
Consider on arithmetical expression:
z>=y>=x? 100:200
= (z >= y >= x? 100: 200)
= (4 >= 4 >= 3? 100: 200)
= ((4 >= 4) >= 3? 100: 200)
= (1 >= 3? 100: 200)
= (0? 100: 200)
= 200
10)
(a!= 10) && (b = 50)
= (30! = 10) && (50)
= 1 && 50
= 1
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.