Professional Documents
Culture Documents
Tricky C Questions For GATE
Tricky C Questions For GATE
Tricky C Questions For GATE
Search
Custom Search
Search
!"
So, i=7+7+7=21
What is break point?
Operator tutorial.
(6) What will be output if you will compile
and execute the following c code?
void main(){
int a=2;
if(a==2){
a=~a+2<<1;
printf("%d",a);
}
else
{ break;
}
}
(a)It will print nothing.
(b)-3
(c)-2
(d)1
(e)Compiler error
Output: (e)
Explanation:
Keyword break is not part of if-else
statement. Hence it will show compiler
error: Misplaced break
Where we can use break keyword?
Control statement tutorial
(7) What will be output if you will compile
and execute the following c code?
void main(){
int a=10;
printf("%d %d %d",a,a++,++a);
}
(a)12 11 11
(b)12 10 10
(c)11 11 12
(d)10 10 12
(e)Compiler error
Output: (a)
Explanation:
In c printf function follows cdecl
parameter passing scheme. In this scheme
parameter is passed from right to left
direction.
Structure tutorial
More questions
(52) What will be output if you will
compile and execute the following c code?
void main(){
static char *s[3]={"math","phy","che"};
typedef char *( *ppp)[3];
static ppp p1=&s,p2=&s,p3=&s;
char * (*(*array[3]))[3]={&p1,&p2,&p3};
char * (*(*(*ptr)[3]))[3]=&array;
p2+=1;
p3+=2;
printf("%s",(***ptr[0])[2]);
}
(a) math
(b) phy
(c) che
(d) Compiler error
(e) None of these
Answer: (c)
Explanation:
Here
ptr: is pointer to array of pointer to
string.
P1, p2, p3: are pointers to array of
string.
array[3]: is array which contain pointer to
array of string.
Pictorial representation:
Operator tutorial.
(70) What will be output if you will
compile and execute the following c code?
int dynamic(int,...);
void main(){
int x,y;
x=dynamic(2,4,6,8,10,12,14);
y=dynamic(3,6,9,12);
clrscr();
printf("%d %d ",x,y);
getch();
}
int dynamic(int s,...){
void *ptr;
ptr=...;
(int *)ptr+=2;
s=*(int *)ptr;
return s;
}
(a) 8 12
(b) 14 12
(c) 2 3
(d) Compiler error
(e) None of these
Answer: (a)
Explanation:
In c three continuous dots is known as
ellipsis which is variable number of
arguments of function. In this example ptr
is generic pointer which is pointing to
first element of variable number of
argument. After incrementing it will point
third element.
What is variable number of argument?
(71) What will be output if you will
compile and execute the following c code?
int extern x;
void main()
printf("%d",x);
x=2;
getch();
}
int x=23;
(a) 0
(b) 2
(c) 23
(d) Compiler error
(e) None of these
Answer: (c)
Explanation:
extern variables can search the declaration
of variable any where in the program.
Properties of extern storage class.
(72) What will be output if you will
compile and execute the following c code?
void main(){
int i=0;
if(i==0){
i=((5,(i=3)),i=1);
printf("%d",i);
}
else
printf("equal");
}
(a) 5
(b) 3
(c) 1
(d) equal
(e) None of above
Answer: (c)
Explanation:
Comma operator.
Operator tutorial.
(73) What will be output if you will
compile and execute the following c code?
void main(){
int a=25;
clrscr();
printf("%o %x",a,a);
getch();
}
(a) 25 25
(b) 025 0x25
(c) 12 42
(d) 31 19
(e) None of these
Answer: (d)
Explanation:
%o is used to print the number in octal
number format.
%x is used to print the number in
hexadecimal number format.
Note: In c octal number starts with 0 and
hexadecimal number starts with 0x.
What is octal number?
What is hexadecimal number?
(74) What will be output if you will
compile and execute the following c code?
#define message "union is\
power of c"
void main(){
clrscr();
printf("%s",message);
getch();
}
(a) union is power of c
(b) union ispower of c
(c) union is
Power of c
(d) Compiler error
(e) None of these
Answer: (b)
Explanation:
If you want to write macro constant in new
line the end with the character \.
Preprocessor tutorial.
(75) What will be output if you will
compile and execute the following c code?
#define call(x) #x
void main(){
printf("%s",call(c/c++));
}
(a)c
(b)c++
(c)#c/c++
(d)c/c++
(e)Compiler error
Answer: (d)
Explanation:
# is string operator. It converts the macro
function call argument in the string. First
see the intermediate file:
test.c 1:
test.c 2: void main(){
test.c 3: printf("%s","c/c++");
test.c 4: }
test.c 5:
It is clear macro call is replaced by its
argument in the string format.
What is # and ##?
Preprocessor tutorial?
(75) What will be output if you will
compile and execute the following c code?
void main(){
if(printf("cquestionbank"))
printf("I know c");
else
printf("I know c++");
}
(a) I know c
(b) I know c++
(c) cquestionbankI know c
(d) cquestionbankI know c++
(e) Compiler error
Answer: (c)
Explanation:
Return type of printf function is integer
which returns number of character it prints
including blank spaces. So printf function
inside if condition will return 13. In if
condition any non- zero number means true
so else part will not execute.
Prototype of printf function.
(1)
#include"stdio.h"
void main(){
long double a=55555;
clrscr();
printf("%.2LE,%.2Le",a);
getch();
}
What will be output if you will execute above code?
(a) 5.56e+04, 5.56E+04
(b) 5.6e+04, 5.6E+04
(c) 5.56E+04, 5.56e+04
(d)Compiler error.
(e)None of the above.
(2)
#include"stdio.h"
void main(){
signed a=5;
unsigned b=5;
clrscr();
if(a==b)
printf("EQUAL");
else
printf("UNEQUAL");
getch();
}
What will be output if you will execute above code?
(a) EQUAL
(b) UNEQUAL
(c) Print nothing
(d) Compiler error.
(e) None of the above
(3)
#include"stdio.h"
void main(){
fputs("STANDARD PRINTER DEVICE",stdprn);
getch();
}
What will be output if you will execute above code?
(a) STANDARD PRINTER DEVICE (on the paper)
(b) STANDARD PRINTER DEVICE (on the standard output
device)
(c) Print nothing
(d)Compiler error.
(e)None of the above.
(4)
#include"stdio.h"
void main(){
char a='\';
clrscr();
printf("%c",a);
getch();
}
What will be output if you will execute above code?
(a)\
(b)\\
(c)Print nothing
(d)Compiler error.
(e)None of the above.
(5)
#include"stdio.h"
void main(){
char a='\7',b='\8';
clrscr();
printf("%d %d",a,b);
getch();
}
What will be output if you will execute above code?
(a) 7 8
(b) 7 56
(c) 55 56
(d) Compiler error.
(e) None of the above.
(6)
#include"stdio.h"
void main(){
char a='\10';
char *str1="cquestion",*str2="bank";
clrscr();
printf("%s%c%s",str1,a,str2);
getch();
}
What will be output if you will execute above code?
(a) cquestionbank
(b) cquestioba
(c) cquestiobank
(d) Compiler error.
(e) None of the above.
(7)
#include"stdio.h"
void main(){
char a='\11';
char *str1="cquestion",*str2="bank";
clrscr();
printf("%d",printf("%s%c%s",str1,a,str2));
getch();
}
What will be output if you will execute above code?
(a) cquestionbank
(b) cquestionbank14
(c) cquestion bank14
(d)Compiler error.
(e)None of the above.
(8)
#include"stdio.h"
void main(){
char a='\12';
char *str1="cquestion",*str2="bank";
clrscr();
printf("%s%c%s",str1,a,str2);
getch();
}
What will be output if you will execute above code?
(a) cquestionbank
(b) cquestion
bank
(c) bankcquestion
(d) Compiler error.
(e) None of the above.
(9)
#include"stdio.h"
void main(){
char a='\377';
clrscr();
printf(2+"%d%o",a);
getch();
}
What will be output if you will execute above code?
(a) 379
(b) 377
(c) 177777
(d) Compiler error.
(e) None of the above.
(10)
#include"stdio.h"
void main(){
char a='\378';
clrscr();
printf("%o",a);
getch();
}
What will be output if you will execute above code?
(a) 177777
(b) 378
(c) 377
(d) Compiler error.
(e) None of the above.
(11)
void main(){
int goto=5;
printf("%d",goto);
getch()
}
What will be output if you will execute above code?
(a)5
(b)10
(c)15
(d)Compiler error.
(e)None of the above.
(12)
void main(){
long int 1a=5l;
printf("%ld",1a);
getch();
}
What will be output if you will execute above code?
(a)5
(b)51
(c)235
(d)Compiler error.
(e)None of the above.
(13)
void main(){
Char * emp name=”raja”;
printf("%s",emp name);
getch();
}
What will be output if you will execute above code?
(a)raja
(b)null
(c)Address of variable emp name
(d)Compiler error.
(e)None of the above.
(14)
void main(){
long int new=5l;
printf("%ld",new);
getch();
}
What will be output if you will execute above code?
(a)5
(b)10
(c)15
(d)Compiler error.
(e)None of the above.
(15)
void main(){
long int _=5l;
printf("%ld",_);
getch();
}
What will be output if you will execute above code?
(a)5
(b)10
(c)15
(d)Compiler error.
(e)None of the above.
(16)
void main(){
char * __WORLD__="world";
clrscr();
printf("%s ",__WORLD__);
getch();
}
What will be output if you will execute above code?
(a)world
(b)worl
(c)null
(d)Compiler error.
(e)None of the above.
(17)
void main(){
char * __TIME__="world";
clrscr();
printf("%s ",__TIME__);
getch();
}
What will be output if you will execute above code?
(a)world
(b)Current time
(c)null
(d)Compiler error.
(e)None of the above.
(18)
void main(){
long int a;
(float)a=6.5;
printf("%f",a);
getch();
}
What will be output if you will execute above code?
(a)6
(b)7
(c)6.5
(d)Compiler error.
(e)None of the above.
(19)
void main(){
long int a,b=10;
++a=b++;
printf("%d %d",a,b);
getch();
}
What will be output if you will execute above code?
(a)10 10
(b)11 11
(c)0 11
(d)Compiler error.
(e)None of the above.
(20)
void main(){
long int a,b=5;;
~a=++b + ++b + ++b;
printf("%d %d",++a,++b);
getch();
}
What will be output if you will execute above code?
(a) -10 9
(b) -11 8
(c) -11 9
(d) Compiler error.
(e) None of the above.
(21)
void main(){
int x;
int y;
x+y=10;
x=3;
printf("%d",y);
getch();
}
What will be output if you will execute above code?
(a)0
(b)7
(c)10
(d)Compiler error.
(e)None of the above.
(22)
void main(){
int x=5;
int y=10;
&x=y;
printf("%d %d",x,y);
getch();
}
What will be output if you will execute above code?
(a)5 10
(b)10 5
(c)10 10
(d)Compiler error.
(e)None of the above.
(23)
void main(){
const a=10;
a=~a;
printf("%d",a);
getch();
}
What will be output if you will execute above code?
(a) 10
(b)-11
(c)-10
(d)Compiler error.
(e)None of the above.
(24)
void main(){
const _=10;
int *p=&_;
printf("%d",*p);
getch();
}
What will be output if you will execute above code?
(a)Address of variable _
(b)20
(c)10
(d)Compiler error.
(e)None of the above.
(25)
void main(){
const int *a=12;
a++;
clrscr();
printf("%d",a);
getch();
}
What will be output if you will execute above code?
(a)12
(b)garbage value
(c)13
(d)Compiler error.
(e)None of the above.
output: garbage value
(26) What will be output of the following program ?
void main(){
const int *a=(const int * )12;
*a=(const int *)25;
clrscr();
printf("%d",a);
getch();
}
What will be output if you will execute above code?
(a)12
(b)25
(c)Address of variable a
(d)Compiler error.
(e)None of the above.
(27)
#include"stdio.h"
void main(){
char a='\15';
char *str1="cquestion",*str2="bank";
clrscr();
printf("%s%c%s",str1,a,str2);
getch();
}
What will be output if you will execute above code?
(a) bankstion
(b)cquestionbank
(c)bankcquestion
(d)Compiler error.
(e)None of the above.
Answer:
1. (c)
2. (a)
3. (a)
4. (d)
5. (b)
6. (c)
7. (c)
8. (b)
9. (c)
10. (d)
11. (d)
12. (d)
13. (d)
14. (a)
15. (a)
16. (a)
17. (d)
18. (d)
19. (d)
20. (d)
21. (d)
22. (d)
23. (d)
24. (c)
25. (b)
26. (d)
27. (a)
Explanation:
1. (c) %e or %E represent print the number in
exponential format.
%e means output has small letter e.
%E means output has capital letter e.
2. (a) before any arithmetic operation small data type
convert into higher data type i.e.signedto unsigned.
3. (a) PRINT IN CONNECTED PRINTER DEVICE, OTHERWISE
TURBO C WILL BE HANGED FOR SEARCHING OF PRINTER IN THE
SYSTEM.
4. (d) Character is \ has special meaning in c
programming.
e.g.
‘\0’ represents octal character.
‘\n’ represents new line character. So we cannot use
‘\’ directly.
5. (b) 8 is not octal digit. octal digits
are(0,1,2,3,4,5,6,7).
So ‘\7’ is octal 7
‘\8’ some special character constant.
6. (c) ‘\10’ represent octal 10 i.e. decimal 8 which is
ASCII code of backspaces (only one character)
7. (c) ‘\11’ represent octal 11 i.e. decimal 9 which is
ASCII code of blank space.
8. (b) ‘\12’ represent octal 12 i.e. decimal 10 which
is ASCII code of new line character i.e. send the
cursor to next line
9. (c) ‘\377’ is octal character constant.
%o is used to print octal number system.
10. (d) Highest possible character constant is ‘\377’
which is
Equivalent to decimal 255.
11. (d) invalid variable name. goto is keyword in c.
12. (d) invalid variable name. Variable name must star
from either alphabet or
under score.
13. (d) invalid variable name. Except underscore there
should not be any special character in name of variable
event blank space.
14. (a) We can use c++ keyword in variable name in c
programming.(But should not use ,why ?)
15. (a) Under score is valid keyword in c.
16. (a) __WORLD__ is valid identifier in c programming
language.
But we should not write variable name in the forma like
__xyx__,
__TIME__. Why ?
17. (d) __TIME__ is valid identifier in c programming
language but it is
Predefine global identifier .So a variable not should
not be global
Identifier like __TIME__,__DATE___,__FILE__ etc.
18. (d) After applying any operator in variable name it
always give a value.
(type): urinary type casting operator is not exception
for this.
It is similar to write
3456=5
It is invalid c statement. Because left side of
assignment operator must
Be a variable not any constant.
19. (d) After applying any operator in variable name it
always give a value.
(type): urinary type casting operator is not exception
for this.
It is similar to write
3456=5
It is invalid c statement. Because left side of
assignment operator must
Be a variable not any constant.
20. (d) After applying any operator in variable name it
always give a value.
(type): urinary type casting operator is not exception
for this.
It is similar to write
3456=5
It is invalid c statement. Because left side of
assignment operator must be a variable not any
constant.
21. (d) After applying any operator in variable name it
always give a value.
(type): urinary type casting operator is not exception
for this.
It is similar to write
3456=5
It is invalid c statement. Because left side of
assignment operator must be a variable not any
constant.
22. (d) After applying any operator in variable name it
always give a value.
(type): urinary type casting operator is not exception
for this.
It is similar to write
3456=5
It is invalid c statement. Because left side of
assignment operator must be a variable not any
constant.
23. (d) we Cannot modify a const object.
24. (c) We can assign address of const object to its
pointer.
Underscore is valid variable name.
25. (b) Explanation: Here address of variable a is
constant not variable a. So we can modify variable a.
Initial value of auto type data is garbage.
26. (d) we Cannot modify a const object.
Here address of variable a is constant not variable a.
27. (a) ‘\11’ represent octal 11 i.e. decimal 9 which
is ASCII code of carriage return (return to first
position of that line)
! "
• #
• $!% & &
!" #
$ % " " !
# ' ( ))( ( ' &
& (
*
'
&'
•
%%
+ & & *
%%
&
!" ( ( "
, ' '
) ( " % "
- . % /
•
* ( ( (
- 0 + 1 2
%%
+ ( ,,,
! "#
! "#
,
• 3 +
• 5
•
•
• !
• $
• 4 ! 6
•
• ! ' 6 '
'%'(+ )-&
• !58!26 .!8! 040 :#!
• -4; .!8! %4 0# 2 +#0- 9 !2!0# 2
• : ! 2#2; !25 ! 0#045
• % 040 :#!
• 5 + !5 $0+!: +#0- 6:!6<
• 5 +2 !5 1 <
#2 :0# 2 :0 ! ; :#0-3
1411 :0 ! ; :#0- !25 6 : ;:!3
60# 2 :0 ! ; :#0- !25 6 : ;:!3
6 26!0 2!0 3!27 $# !25 0 : 0- 3 #2 ! $# #2***
6 420 2 $ 664:: 26 $ ! 6-!:!60 : #2 ! 0:#2;***
5!0! 07 040 :#! #2 6
!3#6!1 !#: : ;:!3 #2 6
5:!+ 0- $ +#2; 7:!3#5 #2 6
3 3 :7 3! 040 :#! #2 6
$# -!25 #2; 040 :#! #2 6
6 : ;:!3 0 6! 64 !0 !: ! $ ! 6#:6
:#20 :#3 2431 : 1 0+ 2 HB 4 #2; 1: !< !25 ***
6 420 0- 2431 : $ 664:: 26 $ !27 0+ 8 + ***
! 31 7 !2;4!; : ;:!33#2; 17 6
:#20 ;#8 2 0:#2; $: 3 $#: 0 664:: 26 $ ;#8 2 ***
! F 5#;#0 2431 : # #2 40 0-: 4;- 0- < 7 1 !:5*0-***
;: !0 0 !3 2; B 2431 : 4 #2; 1#2!:7 3#24 #2 6
8!:#!1 #2 6
8!:#!1 #2 6
#2 :0 !2 3 20 #2 !2 !::!7 !0 5 #: 5 #0# 2 #***
:!0 : !25 9 : # 2 %4 0# 2 #2 6
5 0 3 20 $: 3 !2 !::!7 !0 5 #: 5 #0# 2 4***
6 20: 0!0 3 20 #2 6
0:#2; 040 :#! #2 6
: : 6 : 040 :#! #2 6
0:4604: 040 :#! #2 6 !2;4!;
0:4604: 040 :#! #2 6 !2;4!;
6 !2;4!; 6 3 # :
5 * *
5 0 : 0 &
-7 #6! !55: $ : ;:!3
- 9!5 6#3! 2431 : : : 20!0# 2
5 6:#1 04:1 6 6 3 # :
+-!0 # $# /
+:#0 ! 6 : ;:!3 0 $#25 #= $ ! $#
+ & ) ***
+ & ***
6 #20
0 :8# + %4 0# 2
6 %4 0# 2
6 : ;:!33#2; 040 :#!
0:#2; %4 0# 2 !25 !2 + : #2 6
&
& '
!
! ! 6