C Language Questions
C Language Questions
C QUESTION BANK 1
main(){
unsigned int i;
for(i=1;i>-2;i--)
printf("c aptitude");
}
a. c aptitude
c. Infinite loop
d. None of these
main()
{
static int var = 5;
printf("%d ",var--);
if(var)
main();
}.
a.Stack overflow
b.5 4 3 2 1
c.5 5 5 5 5
d.None of these
main()
float i=1.5;
switch(i)
case 1: printf("1");
case 2: printf("2");
default : printf("0");
a. 1
b. 1 2 0
c. Compiler error
d. None of these
main()
printf("Address of a = %d",&a);
printf("Value of a = %d",a);
a. Runtime error
b. Compiler error
c. Code will execute
d. None of these
void main( )
int i;
i=(2,3);
printf("%d",i);
a) 3
b) 2
c) garbage value.
d)none of these.
main()
printf("%d",count);
a. Compiler error
b. 100
c. 200
d. None of these
main()
int *p=(int*)malloc(-1);
printf("%d",p);
main()
printf("%d %d %d",sun,mon,tue);
a. compiler error
b. 1 -1 1
c. 0 1 2
d. none of these
main()
int a=9;
if(a<10)
printf("hello");
printf("world");
else
printf("HELLO WORLD");
a. compiler error
b. HELLO WORLD
c. hello
d. hello world
main()
char j;
for(j=1;100;j++)
printf("%d",j);
a. compiler error
b. infinte loop
d. none of these
if(a[0]=='\0')
return ;
f(a+1);
f(a+1);
printf("%c",a[0]);
main()
f("ABC");
a.CCBCCBA
b.compiler error
c.CCBCCB
d.none of these
main()
int num=1;
while(num<=5)
printf("%d",num);
if(num<2)
goto here;
num++;
fun()
here:
printf("PP");
a. 1 PP
b. compiler error
d. none of these
main()
#define x 10
printf("%d",x++);
a. 10
b. 11
c. compiler error
d. none of these
main()
printf("hello"):
main();
a. Hello
b. Stack overflow
c. Hello will print infinite times
d. None of these
main()
const int x;
x=100;
printf("%d",x);
a. 100
b. runtime error
c. compiler error
d. none of these
15.
main()
char *p="GOOD";
char a[ ]="GOOD";
a.4 1 4 5 4
b.4 4 4 5 4
c.compiler error
d.none of these
16.
main()
extern i;
printf("%d\n",i);
int i=20;
printf("%d\n",i);
a.runtime error
b.compiler error
c.20
d.none of these
17.
main()
int i=5,j=10;
i=i&=j&&10;
printf("%d %d",i,j);
a.1 10
b.10 1
c.compiler error
d.none of these
18.
main()
int i = 3;
b.compiler error
c.runtime error
d.none of these
19.
main()
char p[ ]="%d\n";
p[1] = 'c';
printf(p,65);
a.compiler error
b.runtime error
c.A
d.none of these
20.
main()
int i=5;
printf(%d,i=++i ==6);
a.1
b.compiler error
c.runtime error
d.none of these
21.
main()
{
int i=5;
printf("%d",++i++);
}
a.runtime error
b.7
c.compiler error
d.none of these
22.
main()
char i=0;
for(;i>=0;i++) ;
printf("%d\n",i);
a.no output
b.compiler error
c.-128
d.none of these
23.
main()
while(i++!=0);
printf("%d",i);
a. compiler error
b. runtime error
c.infinite loop
d.none of these
24.
void main()
if(--i){
main();
printf("%d ",i);
a.5 4 3 2 1
b.stack overflow
c.runtime error
d.0 0 0 0
25.
main(){
int a= 0;int b = 20;char x =1;char y =10;
if(a,b,x,y)
printf("hello");
}
a.compiler error
b.hello
c.nothing will print
d.none of these
26.
main()
{
int i=-1;
-i;
printf("i = %d, -i = %d \n",i,-i);
}
a.1 -1
b compiler error
c.-1 1
d.none of these
27.
main()
{
char not;
not=!2;
printf("%d",not);
}
a.0
b.1
c.error
d.none of these
28.
main()
{
main();
}
a.Compiler error
b.stack overflow
c.nothing will happen
d.none of these
29.
main()
{
show();
}
void show()
{
printf("I'm the greatest");
}
a.compiler error
b.runtime error
c.Im greatest
d.none of these
30.
main()
{
int i=0;
for(;i++;printf("%d",i)) ;
printf("%d",i);
}
a.compiler error
b.nothing will print
c.1
d.none of these
31.
main()
{
int i;
printf("%d",scanf("%d",&i)); // value 10 is given as input
here
}
a. 1
b. 10
c. Compiler error
d. None of these
32.
#include<stdio.h>
main()
{
int i=1,j=2;
switch(i)
{
case 1: printf("GOOD");
break;
case j: printf("BAD");
break;
}
}
a. Compiler error
b. GOOD
c. BAD
d. None of these
33.
main()
{
int i=1;
while (i<=5)
{
printf("%d",i);
if (i>2)
goto here;
i++;
}
}
fun()
{
here:
printf("PP");
}
a.pp
b.compiler error
c.runtime error
d.none of these
34.
#include <stdio.h>
#define a 10
main()
{
#define a 50
printf("%d",a);
}
a.10
b.50
c.error
d.none of these
35.
#define square(x) x*x
main()
{
int i;
i = 64/square(4);
printf("%d",i);
}
a.1
b.error
c.64
d.none of these
36.
main()
{
printf("\nab");
printf("\bsi");
printf("\rha");
}
a. hai
b. absiha
c. error
d. none of these
37.
#define int char
main()
{
int i=65;
printf("sizeof(i)=%d",sizeof(i));
}
a.1
b.4
c.error
d.none of these
38.
main()
{
printf("%x",-1<<4);
}
a. error
b. fffffff0
c. -16
d. None of these
39.
main()
{
int i=3;
switch(i)
{
default: printf("zero");
case 1: printf("one");
break;
case 2: printf("two");
break;
case 3: printf("three");
break;
}
}
a.three
b.three zero
c.error
d.none of these
40.
main()
{
static int var = 5;
printf("%d ",var--);
if(var)
main();
}
a.5 5 5 5 5
b.5 4 3 2 1
c.stack overflow
d.none of these
41.
main()
{
float me = 1.1;
double you = 1.1;
if(me==you)
printf("I love U");
else
43.
void main()
{
int const * p=5;
printf("%d",++(*p));
}
a.6
b.compile time error
c.runtime error
d.none of these
44.
main()
{
unsigned int x = 0xffff;
~x;
printf ("%x", x);
}
a.ffff
b.0
c.error
d.none of these
45.
main()
{
printf ("Hermione" "Granger");
}
a. error
b. HermioneGranger
c.runtime error
d.none of these
46.
main()
{
printf(%c,abcdefg[5]);
}
a.e
b.f
c.error
d.none of these
47.
main()
int z,x=5,y=-10,a=4,b=2;
z = x++ - --y * b / a;
}
a.5
b.6.
c.10
d.none of these
48.
main()
int a=10,b;
b=a++ + ++a;
printf("%d,%d,%d,%d",b,a++,a,++a);
}
a. 12,10,11,13
b. 22,11,11,11
c. 12,11,11,11
d. 22,13,13,13
49.
main()
{
int x[] = { 1, 4, 8, 5, 1, 4 };
int *ptr, y;
ptr = x + 4;
y = ptr - x;
}
a. -3
b. 0
c. 4
d. None of these
50.
if (x > 0)
myFunc(--x);
int main()
myFunc(5);
return 0;
}
a. 1, 2, 3, 4, 5, 5,
b. 4, 3, 2, 1, 0, 0,
c. 5, 4, 3, 2, 1, 0,
d. 0, 0, 1, 2, 3, 4,
51.
What is the value of myArray[1][2]; in the sample code above?
main()
int i,j;
int ctr = 0;
int myArray[2][3];
myArray[j][i] = ctr;
++ctr;
}
}
}
a. 1
b. 2
c. 3
d. 5
52.
main()
int m = -14;
int n = 6;
int o;
o = m % ++n;
n += m++ - o;
m <<= (o ^ n) & 3;
printf("%d %d %d",m,n,o);
}
a. m = -26, n = -7, o = 0
b. m = -52, n = -4, o = -2
c. m = -26, n = -5, o = -2
d. none of these
53.
ptr += 5;
a. 56789
0123456789
b.error
c.6 7 8 9
0123456789
d.none of these
54.
main()
int *ptr = y + 2;
printf("%d\n", ptr[ 1 ] );
}
a.6
b.7
c.8
d.9
55.
main()
{int x = 0;
for ( ; ; )
if (x++ == 4)
break;
continue;
}
printf("x=%d\n", x);
}
a.4
b.5
c.0
d.none of these
56.
main()
char *ptr;
ptr = myString;
ptr += 5;
printf("%s",ptr);
}
a. fg
b. efg
c. defg
d. cdefg
57.
main() {
char *ch1="rajesh";
char *ch2;
ch2=(char*)malloc(20);
while(*ch2++ = *ch1++);
printf("%s\n",ch2);
}
a. rajesh
b. empty string
c. error
d. none of these
58.
main(){
int x=5;
printf("%d,%d,%d\n",x,x<<2,x>>2);
}
a. 5 20 5
b. 5 20 1
c. Error
d. None of these
59.
main()
int a[5]={1,2,3,4,5};
int *ptr=(int*)(&a+1);
printf("%d %d",*(a+1),*(ptr-1));
}
a. 2 2
b. 2 1
c. 2 5
d. None of these
60.
main()
int i=3;
int j;
j=sizeof(++i + ++i);
printf("i %d j %d",i,j);
}
a. 4 2
b. 3 2
c. 3 4
d. 3 6
61.
main()
char a[]="abcde";
char *p=a;
p++;
p++;
p[2]='z';
printf("%s",p);
}
a.cde
b.zde
c.cdz
d. abzec
62.
main()
char *p;
char buf[10]={1,2,3,4,5,6,9,8};
p=(buf+1)[5];
printf("%d",p);
}
a. 5
b. 6
c. 9
d. None of these
63.
main()
printf("ABCDE"+sizeof("ABC"));
a. D
b. Error
c. E
d. ABCDE
64.
main()
int a[2];
a[1]=3;
printf("a[1] %d",a[1]);
printf("1[a] %d",1[a]);
a. 3 3
b. 3 0
c. Error
d. None of these
65.
main()
int i=300;
printf("%d",(char)i);
a. 300
b. 44
c. 256
66.
main()
printf("%d",a[1,1][1,2]);
a. 8
b. 3
c. 6
d. Error
67.
main()
printf("%d",sizeof(3.5,3));
a. Float
b. Double
c. Long double
d. Int
68.
main()
float va=3/2.0+1/2;
printf("%.3f",va);
a. 1.500
b. 2.000
c. 0.500
d. None of these
69.
main()
float a[3];
printf("%d",sizeof(a));
printf("%d",sizeof(&a));
a. 12 4
b. 4 12
c. Error
d. None of these
70.
main()
int sum;
enum temp{A,B,C=5,D,E};
sum =A+B+C+D+E;
printf("%d",sum);
a. 20
b. 19
c. 15
d. None of these
71.
main()
static a[3]={1};
int b[3]={1};
printf("%d %d",a[2],b[2]);
a. 1 1
b. 0 undefined
c. 0 0
d. Undefine undefined
72.
main()
int i=10;
i=!i>14;
printf ("i=%d",i);
a. 10
b. 0
c. Error
d. None of these
73.
#define f(g,g2) g##g2
main()
{
int var12=100;
printf("%d",f(var,12));
}
a. 100
b. Error
c. 10012
d. None of these
74.
main()
{
extern int i;
i=20;
printf("%d",sizeof(i));
}
a. Error
b. 4
d. None of these
75.
main()
char *p;
p="%d\n";
p++;
p++;
printf(p-2,300);
a. Error
b. 300
d. None of these
76.
a. 20
b. 0
c. garbage value
d. error!!
77.
main()
{
int i = -3, j = 2 , k = 0,m;
m = ++i && ++j || ++k;
printf("\n %d %d %d %d",i,j,k,m);
}
a. -2 3 0 1
b. -3 2 0 1
c. -2 3 1 1
d. error
78.
What would be the output of the following program.
#define CUBE(x) (x*x*x)
main()
{
int a, b=3;
a=CUBE(b++);
printf ("\n %d %d", a , b);
}
a.64 4
b.27 4
c. 27 6
d. 64 6
79.
80.
What would be the output of the following program.
#include<stdio.h>
main()
{
char str[5]="fast";
static char *ptr_to_array = str;
printf("%s",ptr_to_array);
}
a. Compilation will only give a warning but will proceed to
execute & will display "fast"
b. display "fast" on screen
c. will give a compilation error.
d. none of the above
81.
What will be the output of the following program?
int main()
printf();
return(0);
(a)Run-Time Error
(b)Compile-Time Error
(c)No Output
(d)None of these
82.
What will be the output of the following program?
int main()
printf(NULL);
return(0);
b. Compile-Time Error
c. No Output
d. None of these
83.
What will be the output of the following program?
int main()
return(0);
a. ByeHi!6
b. Hi!Bye6
c. Compile-Time Error
d. None of these
84.
int main()
printf("Hi Friends"+3);
return(0);
a.Hi Friends
b.Friends
c.Hi Friends3
d. None of these
85.
int main()
int main=7;
printf("%d", main);
return main;
printf("Bye");
return(0);
(a)Compile-Time Error
(b)Run-Time Error
(c)7Bye
(d)7
86.
int main()
int val = 5;
printf("%*d", val);
return(0);
(b)5
(c)Compile-Time Error
(d)None of these
87.
int main()
printf("%d",sizeof str);
return(0);
(a)14
(b)Compile-Time Error
(c)15
(d)None of these
88.
What will be the output of the following program? [NOTE: THE USER
INPUT IS: 123456 44 544]
int main()
int a, b, c;
return(0);
(a)Sum=480
(b)Sum=594
(c)Sum=589
(d)None of these
89.
int main()
printf("Hi!");
if (0 || -1)
printf("Bye");
return(0);
(a)No Output
(b)Hi!
(c)Bye
(d)Hi!Bye
90.
int main()
for (;printf(""););
return(0);
(a)Compile-Time error
(c)Executes INFINITELY
(d)None of these
printf("%d",*a++);
int main()
int a[]={1,2,3,4,5,-1};
print(a,5,6,7,8,9,-1);
return(0);
(a)Compile-Time Error
(b)Run-Time Error
(c)12345
(d)56789
92.
int main()
int val=1234;
int* ptr=&val;
printf("%d %d",++val,*ptr);
return(0);
(a)1234 1234
(b)1235 1235
(c)1234 1235
(d)1235 1234
93.
int main()
int (*a)[5];
printf("%d %d",sizeof(*a),sizeof(a));
return(0);
(a)Compile-Time Error
(b)20 4
(c)5 2
(d)None of these
94.
union A {
char ch;
int i;
float f;
}tempA;
int main()
tempA.ch='A';
tempA.i=777;
tempA.f=12345.12345;
printf("%d",tempA.i);
return(0);
(a)Compile-Time Error
(b)12345
(c)Erroneous output
(d)777
95.
int main()
int i=5;
printf("%d %d %d %d %d",++i,i++,i++,i++,++i);
return(0);
(a)Compile-Time Error
(b)10 9 8 7 6
(c)9 8 7 6 6
(d)10 8 7 6 6
96.
main()
int a = 1;
#define p a
printf("%d %d ",a++,p++) ;
a) 1, 0
b) 2, 0
c) 1 2
97.
int g = 10 ;
main()
int a = 10 ;
printf("%d",a) ;
int g ;
a. 10
b. 11
c. error
d. none
98.
int l=1;
for(;;)
{
printf("%d",l++);
if(l>10)
break;
}
}
(d) No error
99.
main()
{int i=0;
for(i=0;i<20;i++)
{switch(i)
case 0:i+=5;
case 1:i+=2;
case 5:i+=5;
default i+=4;
break;}
printf("%d,",i);
}
}
a) 0,5,9,13,17
b) 5,9,13,17
c) 12,17,2
d) Syntax error
100.
Find the output for the following C program
#include<stdio.h>
main()
{
char s1[]="Ramco";
char s2[]="Systems";
s1=s2;
printf("%s",s1);
}
a. Ramco
b. Ramco systems
c. Error
d. None of these