C Questions
C Questions
main()
{
char *p1=“name”;
char *p2;
p2=(char*)malloc(20);
memset (p2, 0, 20);
while(*p2++ = *p1++);
printf(“%sn”,p2);
}
Answer:empty string.
[Link] will be printed as the result of the operation below:
main()
{
int x=20,y=35;
x=y++ + x++;
y= ++y + ++x;
printf(“%d%dn”,x,y);
}
Answer : 5794
[Link] will be printed as the result of the operation below:
main()
{
int x=5;
printf(“%d,%d,%dn”,x,x< <2,x>>2);
}
Answer: 5,20,1
[Link] will be printed as the result of the operation below:
#define swap(a,b) a=a+b;b=a-b;a=a-b;
void main()
{
int x=5, y=10;
swap (x,y);
printf(“%d %dn”,x,y);
swap2(x,y);
printf(“%d %dn”,x,y);
}
int swap2(int a, int b)
{
int temp;
temp=a;
b=a;
a=temp;
return 0;
}
[Link], VITAE
Answer: 10, 5
10, 5
[Link] will be printed as the result of the operation below:
main()
{
char *ptr = ” Cisco Systems”;
*ptr++; printf(“%sn”,ptr);
ptr++;
printf(“%sn”,ptr);
}
Answer:Cisco Systems
isco systems
[Link] will be printed as the result of the operation below:
main()
{
char s1[]=“Cisco”;
char s2[]= “systems”;
printf(“%s”,s1);
}
Answer: Cisco
[Link] will be printed as the result of the operation below:
main()
{
char *p1;
char *p2;
p1=(char *)malloc(25);
p2=(char *)malloc(25);
strcpy(p1,”Cisco”);
strcpy(p2,“systems”);
strcat(p1,p2);
printf(“%s”,p1);
}
Answer: Ciscosystems
[Link] following variable is available in file1.c, who can access it?:
[Link] int average;
Answer: all the functions in the file1.c can access the variable.
[Link] will be the result of the following code?
#define TRUE 0 // some code
while(TRUE)
{
// some code
}
Answer: This will not go into the loop as TRUE is defined as 0.
[Link] will be printed as the result of the operation below:
int x;
int modifyvalue()
[Link], VITAE
{
return(x+=10);
}
int changevalue(int x)
{
return(x+=1);
}
void main()
{
int x=10;
x++;
changevalue(x);
x++;
modifyvalue();
printf("First output:%dn",x);
x++;
changevalue(x);
printf("Second output:%dn",x);
modifyvalue();
printf("Third output:%dn",x);
}
Answer: 12 , 13 , 13
[Link] will be printed as the result of the operation below:
main()
{
int x=10, y=15;
x = x++;
y = ++y;
printf(“%d %dn”,x,y);
}
Answer: 11, 16
[Link] will be printed as the result of the operation below:
main()
{
int a=0;
if(a==0)
printf(“Cisco Systemsn”);
printf(“Cisco Systemsn”);
}
Answer: Two lines with “Cisco Systems” will be printed.
14.
What will be output if you will execute following c code?
#include<stdio.h>
int main(){
int i;
[Link], VITAE
for(i=0;i<5;i++){
int i=10;
printf(" %d",i);
i++;
}
return 0;
}
(A) 10 11 12 13 14
(B) 10 10 10 10 10
(C) 0 1 2 3 4
(D) Infinite loop
(E) Compilation error
15
What will be output if you will execute following c code?
#include<stdio.h>
int main(){
register a,b,x;
scanf("%d %d",&a,&b);
x=a+~b;
printf("%d",x);
return 0;
}
16.
What will be output if you will execute following c code?
#include<stdio.h>
auto int a=5;
int main(){
int x;
x=~a+a&a+a<<a;
printf("%d",x);
return 0;
}
[Link], VITAE
(A) 5
(B) 0
(C) 1
(D) 153
(E) Compilation error
17.
What will be output if you will execute following c code?
#include<stdio.h>
void main(){
register int a,b;
int c;
scanf("%d%d",&a,&b);
c=~a + ~b + ++a + b++;
printf(" %d",c);
}
//User input is: 1 2
(A) -1
(B) 0
(C) 1
(D) 2
(E) Compilation error
18.
What will be output if you will execute following c code?
#include<stdio.h>
#include<conio.h>
void main(){
int arr[3]={10,20,30};
int x=0;
x=++arr[++x]+ ++x+arr[--x];
printf("%d ",x);
}
(A)
23
(B) 43
(C) 22
(D) 44
(E) Compilation error
[Link], VITAE
19.
What will be output if you will execute following c code?
#include<stdio.h>
#include<conio.h>
void main(){
int a[]={10,20,30,40};
int i=3,x;
x=1*a[--i]+2*a[--i]+3*a[--i];
printf("%d",x);
}
(A) 60
(B) 50
(C) 40
(D) 30
(E) Compilation error
20.
What will be output if you will execute following c code?
#include<stdio.h>
#include<conio.h>
void main(){
static int a[][2][3]={0,1,2,3,4,5,6,7,8,9,10,11,12};
int i=-1;
int d;
d=a[i++][++i][++i];
printf("%d",d);
}
(A) 9
(B) 10
(C) 11
(D) 12
(E) Compilation error
21.
What will be output if you will execute following c code?
#include<stdio.h>
#include<conio.h>
void main(){
int i=3,val;
[Link], VITAE
val=sizeof (f(i)+ +f(i=1)+ +f(i-1));
printf("%d %d",val,i);
}
int f(int num){
return num*5;
}
(A) 2 2
(B) 3 3
(C)
23
(D) 15 0
(E) Compilation error
22.
What will be output if you will execute following c code?
#include<stdio.h>
#include<conio.h>
void main(){
int x,a=3;
x=+ +a+ + +a+ + +5;
printf("%d %d",x,a);
}
(A) 10 3
(B) 11 3
(C) 10 5
(D) 11 3
(E) Compilation error
23.
What will be output if you will execute following c code?
#include<stdio.h>
#include<conio.h>
void main(){
int num,i=0;
num=-++i+ ++-i;
printf("%d",num);
}
(A) 0
(B) 1
(C) -2
[Link], VITAE
(D) 2
(E) Compilation error
24.
What will be output if you will execute following c code?
#include<stdio.h>
#include<conio.h>
void main(){
int num,a=5;
num=-a--+ +++a;
printf("%d %d",num,a);
}
(A)
1 5
(B) -1 6
(C) 1 6
(D) 0 5
(E) Compilation error
25.
What will be output if you will execute following c code?
#include<stdio.h>
#include<conio.h>
void main(){
int num,a=15;
num=- - - -a--;
printf("%d %d",num,a);
}
(A) 15 15
(B) 14 14
(C)
14 15
(D) 15 14
(E) Compilation error
26
What will be output if you will execute following c code?
#include<stdio.h>
#include<conio.h>
void main(){
[Link], VITAE
int x,a=2;
x=++a,++a,a++;
printf("%d %d",x,a);
}
(A) 5 5
(B) 3 5
(C) 4 5
(D) 5 4
(E) Compilation error
27.
What will be output if you will execute following c code?
#include<stdio.h>
#include<conio.h>
void main(){
int x,i=2;
x=~-!++i;
printf("%d",x);
}
(A) -2
(B) -1
(C) 0
(D) 1
(E) Compilation error
28.
What will be output if you will execute following c code?
#include<stdio.h>
int main(){
static double *p,*q,*r,*s,t=5.0;
double **arr[]={&p,&q,&r,&s};
int i;
*p=*q=*r=*s=t;
for(i=0;i<4;i++)
printf("%.0f ",**arr[i]);
return 0;
}
(A) 5 5 5 5 5
(B) 5 6 7 8 9
[Link], VITAE
(C) 5 4 3 2 1
(D) Infinte loop
(E) Compilation error
29.
What will be output if you will execute following c code?
int main(){
float x;
x=0.35==3.5/10;
printf("%f",x);
return 0;
}
(A) 0.000000
(B) 1.000000
(C) 0.350000
(D) 3.500000
(E) Compilation error
30.
What will be output if you will execute following c code?
#include<stdio.h>
#include<conio.h>
void main(){
int arr[]={6,12,18,24};
int x=0;
x=arr[1]+(arr[1]=2);
printf("%d",x);
}
(A)
4
(B) 8
(C) 14
(D) 14
(E) Compilation error
31.
What will be output if you will execute following c code?
[Link], VITAE
#include<stdio.h>
#include<conio.h>
void main(){
int a=1,x;
x=sq(++a)+sq(a++)+sq(a++);
printf("%d",x);
}
int sq(int num){
return num*num;
}
(A) 15
(B) 16
(C) 17
(D) 18
(E) Compilation error
32.
What will be output if you will execute following c code?
void main(){
printf("%c",*"abcde");
}
(A) Acbcd
(B) E
(C) A
(D) Null
(E) Compilation error
33.
What will be output if you will execute following c code?
void main(){
printf("%d","abcde"-"abcde");
}
(A) 0
(B) -1
(C) 1
(D) Garbage
[Link], VITAE
(E) Compilation error
34.
What will be output when you will execute following c code?
#include<stdio.h>
void main(){
printf("%d\t",sizeof(6.5));
printf("%d\t",sizeof(90000));
printf("%d",sizeof('A'));
}
(A) 4 2 1
(B) 8 2 1
(C) 4 4 1
(D) 8 4 1
(E) 8 4 2
35.
Consider on following declaring of enum.
(i) enum cricket {Gambhir,Smith,Sehwag}c;
(ii) enum cricket {Gambhir,Smith,Sehwag};
(iii) enum {Gambhir,Smith=-5,Sehwag}c;
(iv) enum c {Gambhir,Smith,Sehwag};
(A)
Only (i) is correct declaration
(B) Only (i) and (ii) is correct declaration
(C) Only (i) and (iii) are correct declaration
(D) Only (i),(ii) and are correct declaration
(E) All four are correct declaration
35.
What will be output when you will execute following c code?
#include<stdio.h>
void main(){
signed x;
unsigned y;
x = 10 +- 10u + 10u +- 10;
y = x;
if(x==y)
printf("%d %d",x,y);
else if(x!=y)
[Link], VITAE
printf("%u %u",x,y);
}
(A) 0 0
(B) 65536 -10
(C) 0 65536
(D) 65536 0
(E) Compilation error
36.
Which of the following is not modifier of data type in c?
(A) Extern
(B) Interrupt
(C) Huge
(D) Register
(E) All of these are modifiers of data type
37.
What will be output when you will execute following c code?
#include<stdio.h>
void main(){
double num=5.2;
int var=5;
printf("%d\t",sizeof(!num));
printf("%d\t",sizeof(var=15/2));
printf("%d",var);
}
(A) 4 2 7
(B) 4 4 5
(C) 2 2 5
(D) 2 4 7
(E) 8 2 7
38.
What will be output when you will execute following c code?
#include<stdio.h>
void main(){
const int *p;
int a=10;
p=&a;
[Link], VITAE
printf("%d",*p);
}
(A) 0
(B) 10
(C) Garbage value
(D) Any memory address
(E) Error: Cannot modify const object
38.
Consider on following declaration:
(i) short i=10;
(ii) static i=10;
(iii) unsigned i=10;
(iv) const i=10;
(A)
Only (iv) is incorrect
(B) Only (ii) and (iv) are incorrect
(C) Only (ii),(iii) and (iv) are correct
(D) Only (iii) is correct
(E) All are correct declaration
39.
What will be output when you will execute following c code?
#include<stdio.h>
void main(){
int a= sizeof(signed) +sizeof(unsigned);
int b=sizeof(const)+sizeof(volatile);
printf("%d",a+++b);
}
(A) 10
(B) 9
(C) 8
(D) Error: Cannot find size of modifiers
(E) Error: Undefined operator +++
40.
What will be output when you will execute following c code?
[Link], VITAE
#include<stdio.h>
void main(){
signed x,a;
unsigned y,b;
a=(signed)10u;
b=(unsigned)-10;
y = (signed)10u + (unsigned)-10;
x = y;
printf("%d %u\t",a,b);
if(x==y)
printf("%d %d",x,y);
else if(x!=y)
printf("%u %u",x,y);
}
(A) 10 -10 0 0
(B) 10 -10 65516 -10
(C) 10 -10 10 -10
(D) 10 65526 0 0
(E) Compilation error
41.
Which of the following is integral data type?
(A) void
(B) char
(C) float
(D) double
(E) None of these
42.
What will be output when you will execute following c code?
#include<stdio.h>
void main(){
volatile int a=11;
printf("%d",a);
}
[Link], VITAE
(B) Garbage
(C) -2
(D) We cannot predict
(E) Compilation error
43.
What is the range of signed int data type in that compiler in which size of int is two byte?
(A) -255 to 255
(B) -32767 to 32767
(C) -32768 to 32768
(D) -32767 to 32768
(E) -32768 to 32767
44.
What will be output when you will execute following c code?
#include<stdio.h>
const enum Alpha{
X,
Y=5,
Z
}p=10;
void main(){
enum Alpha a,b;
a= X;
b= Z;
printf("%d",a+b-p);
(A) -4
(B) -5
(C) 10
(D) 11
(E) Error: Cannot modify constant object
45.
What will be output when you will execute following c code?
#include<stdio.h>
void main(){
char a=250;
int expr;
[Link], VITAE
expr= a+ !a + ~a + ++a;
printf("%d",expr);
}
(A) 249
(B) 250
(C) 0
(D) -6
(E) Compilation error
46.
Consider on order of modifiers in following declaration:
47.
What will be output when you will execute following c code?
#include<stdio.h>
void main(){
int a=-5;
unsigned int b=-5u;
if(a==b)
printf("Avatar");
else
printf("Alien");
}
(A) Avatar
(B) Alien
(C) Run time error
[Link], VITAE
(D) Error: Illegal assignment
48.
What will be output when you will execute following c code?
#include<stdio.h>
extern enum cricket x;
void main(){
printf("%d",x);
}
const enum cricket{
Taylor,
Kallis=17,
Chanderpaul
}x=Taylor|Kallis&Chanderpaul;
(A) 0
(B) 15
(C) 16
(D) 17
(E) Compilation error
49.
Which of the following is not derived data type in c?
(A) Function
(B) Pointer
(C) Enumeration
(D) Array
(E) All are derived data type
void main(){
printf("%d %d",x,varp.q);
}
[Link], VITAE
Choose all that apply:
(A) 0 11
(B) 5 10
(C) 4 11
(D)
0 10
(E) Compilation error
[Link], VITAE
}
(55)what will be output of the following program?
void main()
{
int a=2,b=7,c=10;
c=a==b;
printf("%d",c);
}
(56)what will be output of the following program?
void main()
{
int x;
x=10,20,30;
printf("%d",x);
}
(57) what will be output of the following program?
void main()
{
int a=0,b=10;
if(a=0)
{
printf("true");
}
else
{
printf("false");
}
}
(58) what will be output of the following program?
void main()
{
int a;
a=015 + 0x71 +5;
printf("%d",a);
}
(59) what will be output of the following program?
void main()
{
printf("%d %d %d",sizeof(3.14),sizeof(3.14f),sizeof(3.14L));
}
[Link], VITAE
}
(61) what will be output of the following program?
void main(){
int a=2;
a=a++ + ~++a;
printf("%d",a);
}
#include<stdio.h>
void main(){
int a=5,b=10,c=1;
if(a&&b>c){
printf("cquestionbank");
}
else{
break;
}
}
(A) Cquestionbank
(B) It will print nothing
(C) Run time error
(D) Compilation error
[Link], VITAE
(E) None of the above
Keyword break is not syntactical part of if-else statement. So we cannot use break keyword in if-
else statement. This keyword can be use in case of loop or switch case statement.
Hence when you will compile above code compiler will show an error message: Misplaced
break.
66. What will be output when you will execute following c code?
PRINT is macro constant. Macro PRINT will be replaced by its defined statement just before the
actual compilation starts. Above code is converted as:
void main(){
int x=1;
if(x--)
printf("Star Wars");
printf(" Psycho");
else
printf("The Shawshank Redemption");
}
If you are not using opening and closing curly bracket in if clause, then you can write only one
statement in the if clause. So compiler will think:
(i)
if(x--)
printf("Star Wars");
[Link], VITAE
printf(" Psycho");
You cannot write else clause without any if clause. It is cause of compilation error. Hence
compiler will show an error message: Misplaced else
67. What will be output when you will execute following c code?
As we know in c zero represents false and any non-zero number represents true. So in the above
code:
(0.001 – 0.1f) is not zero so it represents true. So only if clause will execute and it will print:
David Beckham on console.
But it is bad programming practice to write constant as a condition in if clause. Hence compiler
will show a warning message: Condition is always true
Since condition is always true, so else clause will never execute. Program control cannot reach at
else part. So compiler will show another warning message:
Unreachable code
68. What will be output when you will execute following c code?
#include<stdio.h>
void main(){
int a=100;
[Link], VITAE
if(a>10)
printf("M.S. Dhoni");
else if(a>20)
printf("M.E.K Hussey");
else if(a>30)
printf("A.B. de villiers");
}
M.S Dhoni
(C)
M.E.K Hussey
A.B. de Villiers
In case of if – if else – if else … Statement if first if clause is true the compiler will never check
rest of the if else clause and so on.
#include<stdio.h>
void main(){
int x=-1,y=-1;
if(++x=++y)
printf("R.T. Ponting");
else
printf("C.H. Gayle");
}
[Link], VITAE
As we know ++ is pre increment operator in the above statement. This operator increments the
value of any integral variable by one and return that value. After performing pre increments
above statement will be:
0=0
In C language it is illegal to assign a constant value to another constant. Left side of = operator
must be a container i.e. a variable. So compiler will show an error message: Lvalue required
In c if you assign any value to variable but you don’t perform any operator or perform operation
only using unary operator on the variable the complier will show a warning message: Variable is
assigned a value that is never
#include<stdio.h>
void main(){
if(sizeof(void))
printf("M. Muralilidaran");
else
printf("Harbhajan Singh");
}
(A) M. Muralilidaran
(B) Harbhajan Singh
(C) Warning: Condition is always false
(D) Compilation error
(E) None of the above
It illegal to find size of void data type using sizeof operator. Because size of void data type is
meaning less.
[Link], VITAE
(E) None of the above
q/n*m
Precedence of both operators is same. Hence associate will decide which operator will execute
first. Since Associate is left to right. So / operator will execute then * operator will execute.
=q/n*m
= 20 / 10 * 5
=2*5
=10
As we know in c zero represents false and any non-zero number represents true. Since 10 is non-
zero number so if clause will execute and print: William Gates
Since in else clause there is not any opening and closing curly bracket. So compiler will treat
only one statement as a else part. Hence last statement i.e.
printf(" Carlos Slim Helu");
is not part of if-else statement. So at the end compiler will also print: Carlos Slim Helu
So output of above code will be:
William Gates Carlos Slim Helu
72. What will be output when you will execute following c code?
#include<stdio.h>
void main(){
if(!printf("Mukesh Ambani"))
if(printf(" Lakashmi Mittal"))
}
[Link], VITAE
Return type of printf function is int. This function return a integral value which is equal to
number of characters a printf function will print on console. First of all printf function will:
Mukesh Ambani. Since it is printing 13 character so it will return 13. So,
!printf("Mukesh Ambani")
= !13
=0
In c language zero represents false. So if(0) is false so next statement which inside the body of
first if statement will not execute.
73. What will be output when you will execute following c code?
#include<stdio.h>
void main(){
if("ABC") printf("Barack Obama\n");
if(-1) printf("Hu Jintao\n");
if(.92L) printf("Nicolas Sarkozy\n");
if(0) printf("Ben Bernanke\n");
if('W') printf("Vladimir Putin\n");
}
“ABC”: It is string constant and it will always return a non-zero memory address.
0.92L: It is long double constant.
‘W’: It is character constant and its ASCII value is
As we know in c language zero represents false and any non-zero number represents true. In this
program condition of first, second, third and fifth if statements are true.
[Link], VITAE
74. What will be output when you will execute following c code?
#include<stdio.h>
void main(){
if(0xA)
if(052)
if('\xeb')
if('\012')
printf("Tom hanks");
else;
else;
else;
else;
}
#include<stdio.h>
void main(){
int a=10;
if(printf("%d",a>=10)-10)
for(;;)
break;
else;
}
[Link], VITAE
(C) 1
(D) Compilation error: Misplaced else
(E) Infinite loop
Return type of printf function is int. This function return a integral value which is equal to
number of charcters printf function will print on console.
Operator >= will return 1 if both operands are either equal or first operand is grater than second
operand. So a>=10 will return 1 since a is equal to [Link] printf function will print 1. Since this
function is printing only one character so it will also return 1. So, printf("%d",a>=10) - 10
= 1 - 10
= -9
Since -9 is non-zero number so if(-9) is true condition and if clause will execute.
76. What will be output when you will execute following c code?
#include<stdio.h>
void main(){
int a=5,b=10;
if(++a||++b)
printf("%d %d",a,b);
else
printf("John Terry");
}
(A) 5 10
(B) 6 11
(C) 6 10
(D) 5 11
(E) John Terry
Consider the following expression:
++a || ++b
In this expression || is Logical OR operator. Two important properties of this operator are:
Property 1:
(Expression1) || (Expression2)
|| operator returns 0 if and only if both expressions return a zero otherwise it || operator returns 1.
Property 2:
To optimize the execution time there is rule, Expression2 will only evaluate if and only if
Expression1 return zero.
In this program initial value of a is 5. So ++a will be 6. Since ++a is returning a non-zero so ++b
will not execute and if condition will be true and if clause will be executed.
77. What will be output when you will execute following c code?
[Link], VITAE
#include<stdio.h>
void main(){
static int i;
for(;;)
if(i+++"The Matrix")
printf("Memento");
else
break;
}
78. What will be output when you will execute following c code?
#include<stdio.h>
void main(){
int x=1;
if(x--)
printf("The Godfather");
--x;
else
printf("%d",x);
}
If you are not using { and } in if clause then you can write only one statement. Otherwise it will
cause of compilation error: Misplace else
79. What will be output when you will execute following c code?
#include<stdio.h>
void main(){
if('\0');
else if(NULL)
printf("cquestionbank");
[Link], VITAE
else;
}
(A) Cquestionbank
(B) It will print nothing
(C) Warning: Condition is always true
(D) Warning: Unreachable code
(E) Compilation error: if statement without any body
‘\0’ is null character constant. Its ASCII value is zero. if(0) means false so program control will
check it else if clause.
NULL is macro constant which has been defined in stdio.h which also returns zero.
80. What will be output when you will execute following c code?
#include<stdio.h>
void main(){
int a=5,b=10;
clrscr();
if(a<++a||b<++b)
printf("%d %d",a,b);
else
printf("John Terry");
}
(A) 5 10
(B) 6 11
(C) 6 10
(D) Compilation error
(E) John Terry
a<++a||b<++b
In the above expression || is logical OR operator. It divides any expression in the sub
expressions. In this way we have two sub expressions:
(1) a<++a
(2) b<++b
In the expression: a< ++a
There are two operators. There precedence and associate are:
[Link], VITAE
Precedence Operator Associate
1 ++ Right to left
From table it is clear first ++ operator will perform the operation then < operator.
One important property of pre-increment (++) operator is: In any expression first pre-increment
increments the value of variable then it assigns same final value of the variable to all that
variables. So in the expression: a < ++a
Initial value of variable a is 5.
Step 1: Increment the value of variable a in whole expression. Final value of a is 6.
Step 2: Now start assigning value to all a in the expression. After assigning 6 expression will be:
6<6
Since condition is false .So second expression i.e. b<++b will be evaluated. Again 11 < 11 is
false. So || will operator will return zero and else clause will execute.
81. What will be output when you will execute following c code?
#include<stdio.h>
void main(){
int x=1,y=2;
if(--x && --y)
printf("x=%d y=%d",x,y);
else
printf("%d %d",x,y);
}
(A) 1 2
(B) x=1 y=2
(C) 0 2
(D) x=0 y=1
(E) 0 1
In this expression && is Logical AND operator. Two important properties of this operator are:
Property 1:
(Expression1) && (Expression2)
&& operator returns 1 if and only if both expressions return a non-zero value other wise it &&
operator returns 0.
Property 2:
[Link], VITAE
To optimize the execution time there is rule, Expression2 will only evaluate if and only if
Expression1 return a non-zero value.
In this program initial value of x is 1. So –x will be zero. Since -–x is returning zero so -–y will
not execute and if condition will be false. Hence else part will be executed.
82. What will be output when you will execute following c code?
#include<stdio.h>
void main(){
signed int a=-1;
unsigned int b=-1u;
if(a==b)
printf("The Lord of the Rings");
else
printf("American Beauty");
}
#include<stdio.h>
void main(){
char c=256;
char *ptr="Leon";
if(c==0)
while(!c)
if(*ptr++)
printf("%+u",c);
else
break;
}
(A) +256+256+256+256
(B) 0000
(C) +0+0+0+0
(D) It will print +256 at infinite times
(E) Compilation error
[Link], VITAE
In the above program c is signed (default) char variable. Range of signed char variable in Turbo
c is from -128 to 127. But we are assigning 256 which is beyond the range of variable c. Hence
variable c will store corresponding cyclic value according to following diagram:
Since 256 is positive number move from zero in clock wise direction. You will get final value of
c is zero.
if(c==0)
It is true since value of c is zero.
Negation operator i.e. ! is always return either zero or one according to following rule:
!0 = 1
!(Non-zero number) = 0
So,
!c = !0 =1
As we know in c zero represents false and any non-zero number represents true. So
while(!c) i.e. while(1) is always true.
In the above program prt is character pointer. It is pointing to first character of string “Leon”
according to following diagram:
In the above figure value in circle represents ASCII value of corresponding character.
Initially *ptr means ‘L’. So *ptr will return ASCII value of character constant ‘L’ i.e. 76
if(*ptr++) is equivalent to : if(‘L’) is equivalent to: if(76) . It is true so in first iteration it will
print +0. Due to ++ operation in second iteration ptr will point to character constant ‘e’ and so
on. When ptr will point ‘\0’ i.e. null character .It will return its ASCII value i.e. 0. So if(0) is
false. Hence else part will execute.
84. What will be output when you will execute following c code?
#include<stdio.h>
void main(){
int a=2;
if(a--,--a,a)
[Link], VITAE
printf("The Dalai Lama");
else
printf("Jim Rogers");
}
(A) The Dalai Lama
(B) Jim Rogers
(C) Run time error
Compilation error: Multiple parameters in
(D)
if statement
(E) None of the above
(A) [Link]
(B) [Link]
86. What will be output when you will execute following c code?
#include<stdio.h>
[Link], VITAE
void main(){
int movie=1;
switch(movie<<2+movie){
default:printf("3 Idiots");
case 4: printf(" Ghajini");
case 5: printf(" Krrish");
case 8: printf(" Race");
}
}
(A) 3 Idiots Ghajini Krrish Race
(B) Race
(C) Krrish
(D) Ghajini Krrish Race
(E) Compilation error
87. What will be output when you will execute following c code?
#include<stdio.h>
#define L 10
void main(){
auto money=10;
switch(money,money*2){
case L: printf("Willian");
break;
case L*2:printf("Warren");
break;
case L*3:printf("Carlos");
break;
default: printf("Lawrence");
case L*4:printf("Inqvar");
break;
}
}
(A) Willian
(B) Warren
(C) Lawrence Inqvar
(D) Compilation error: Misplaced default
(E) None of the above
88. What will be output when you will execute following c code?
#include<stdio.h>
void main(){
int const X=0;
switch(5/4/3){
case X: printf("Clinton");
[Link], VITAE
break;
case X+1:printf("Gandhi");
break;
case X+2:printf("Gates");
break;
default: printf("Brown");
}
}
(A) Clinton
(B) Gandhi
(C) Gates
(D) Brown
(E) Compilation error
89. What will be output when you will execute following c code?
#include<stdio.h>
enum actor{
SeanPenn=5,
AlPacino=-2,
GaryOldman,
EdNorton
};
void main(){
enum actor a=0;
switch(a){
case SeanPenn: printf("Kevin Spacey");
break;
case AlPacino: printf("Paul Giamatti");
break;
case GaryOldman:printf("Donald Shuterland");
break;
case EdNorton: printf("Johnny Depp");
}
}
[Link], VITAE
switch(*(1+"AB" "CD"+1)){
case 'A':printf("Pulp Fiction");
break;
case 'B':printf("12 Angry Man");
break;
case 'C':printf("Casabance");
break;
case 'D':printf("Blood Diamond");
}
(A) Brazil
(B) Toy story
(C) His Girl Friday
(D) Casino Royale
(E) Compilation error
92.
What will be output when you will execute following c code?
#include<stdio.h>
void main(){
switch(5||2|1){
[Link], VITAE
case 3&2:printf("Anatomy of a Murder");
break;
case -~11:printf("Planet of Apes");
break;
case 6-3<<2:printf("The conversation");
break;
case 5>=5:printf("Shaun of the Dead");
}
}
(A) Sangakkara
(B) Sehwag
(C) Steyn
(D) Smith
(E) Compilation error
94. What will be output when you will execute following c code?
#include<stdio.h>
void main(){
switch(0X0){
case NULL:printf("Thierry Henry");
break;
case '\0':printf("Steven Gerrend");
break;
case 0: printf("Kaka");
[Link], VITAE
break;
default: printf("Michael Ballack");
}
}
(A) Thierry Henry
(B) Steven Gerrend
(C) Kaka
(D) Michael Ballack
(E) Compilation error
96. What will be output when you will execute following c code?
#include<stdio.h>
void main(){
unsigned char c=280;
switch(c){
printf("Start\t");
case 280:printf("David Beckham\t");
case 24: printf("Ronaldinho\t");
default: printf("Ronaldo\t");
printf("End");
}
}
(A)
[Link], VITAE
Start David Beckham Ronaldinho Ronaldo End
(B) Start David Beckham Ronaldinho Ronaldo
(C) Start Ronaldinho Ronaldo End
97. What will be output when you will execute following c code?
#include<stdio.h>
#define TRUE 1
void main(){
switch(TRUE){
printf("[Link]");
}
}
(A) [Link]
(B) It will print nothing
(C) Runtime error
(D) Compilation error
(E) None of the above
98. What will be output when you will execute following c code?
#include<stdio.h>
void main(){
static int i;
int j=1;
int arr[5]={1,2,3,4};
switch(arr[j]){
case 1: i++;break;
case 2: i+=2;j=3;continue;
case 3: i%=2;j=4;continue;
default: --i;
}
printf("%d",i);
}
(A) 0
(B) 1
(C) 2
(D) Compilation error
(E) None of the above
[Link], VITAE
99. What will be output when you will execute following c code?
#include<stdio.h>
void main(){
static int i;
int j;
for(j=0;j<=5;j+=2)
switch(j){
case 1: i++;break;
case 2: i+=2;
case 4: i%=2;j=-1;continue;
default: --i;continue;
}
printf("%d",i);
}
(A) 0
(B) 1
(C) 2
100. What will be output when you will execute following c code?
#include<stdio.h>
void main(){
int x=3;
while(1){
switch(x){
case 5/2: x+=x+++x;
case 3%4: x+=x---x;continue;
case 3>=3: x+=!!!x;break;
case 5&&0:x+=~~~x;continue;
default: x+=-x--;
}
break;
}
printf("%d",x);
}
(A) 3
(B) -1
(C) 5
[Link], VITAE
(D) Compilation error
(E) None of the above
[Link], VITAE
(A) I
(B) IPleaseHi
(C) IHi
(D) Compilation error
(E) None of the above
103. What will be output when you will execute following c code?
#include<stdio.h>
void main(){
int a=5;
a=a>=4;
switch(2){
case 0:int a=8;
case 1:int a=10;
case 2:++a;
case 3:printf("%d",a);
}
}
(A) 8
(B) 11
(C) 10
(D) Compilation error
(E) None of the above
104. What will be output when you will execute following c code?
#include<stdio.h>
void main(){
int a=3,b=2;
a=a==b==0;
switch(1){
a=a+10;
}
sizeof(a++);
printf("%d",a);
}
(A) 10
(B) 11
(C) 12
1
(D)
[Link], VITAE
(E) Compilation error
extern int x;
void main(){
clrscr();
do{
do{
printf("%o",x);
}
while(!-2);
}
while(0);
getch();
}
int x=8;
void main(){
int i=2,j=2;
clrscr();
while(i+1?--i:j++)
printf("%d",i);
getch();
}
(107) What will be output of following c code?
void main(){
int x=011,i;
clrscr();
for(i=0;i<x;i+=3){
printf("Start ");
continue;
printf("End");
}
getch();
}
void main(){
int i,j;
[Link], VITAE
i=j=2,3;
clrscr();
while(--i&&j++)
printf("%d %d",i,j);
getch();
}
int r();
void main(){
clrscr();
for(r();r();r()) {
printf("%d ",r());
[Link], VITAE
}
getch();
}
int r(){
int static num=7;
return num--;
}
int i=40;
extern int i;
void main(){
clrscr();
do{
printf("%d",i++);
}
while(5,4,3,2,1,0);
getch();
}
char _x_(int,...);
void main(){
char (*p)(int,...)=&_x_;
clrscr();
for(;(*p)(0,1,2,3,4); )
printf("%d",!+2);
getch();
[Link], VITAE
}
char _x_(int a,...){
static i=-1;
return i+++a;
}
void main(){
int i;
clrscr();
for(i=10;i<=15;i++){
while(i){
do{
printf("%d ",1);
if(i>>1)
continue;
}while(0);
break;
}
}
getch();
}
void main(){
char c=125;
clrscr();
do
printf("%d ",c);
while(c++);
getch();
}
void main(){
int x=123;
int i={
printf("c" "++")
};
for(x=0;x<=i;x++){
printf("%x ",x);
}
[Link], VITAE
getch();
}
119. What will be output of following program?
#include<stdio.h>
void main(){
int a = 320;
char *ptr;
ptr =( char *)&a;
printf("%d ",*ptr);
getch();
}
(A) 2
(B) 320
(C) 64
(D) Compilation error
(E) None of above
As we know int is two byte data byte while char is one byte data byte. char pointer can keep the
address one byte at time.
Binary value of 320 is 00000001 01000000 (In 16 bit)
Memory representation of int a = 320 is:
So ptr is pointing only first 8 bit which color is green and Decimal value is 64.
[Link], VITAE
(B) [Link]
(C) c
(D) Compilation error
p is pointer to function whose parameter is void and return type is also void. r and q is pointer to
function whose parameter is void and return type is int . So they can hold the address of such
function.
Memory representation
[Link], VITAE
So *k = *(&j) since k = &j
*&j = j = 6024
And
**k = **(&j) = *(*&j) = *j = *(&i) = *&i = i = 3
[Link], VITAE
(D) Compilation error
(E) None of above
Here we are performing relational operation between two huge addresses. So first of all both a
and b will normalize as:
a= (0x5999)* (0x10) + (0x0005) =0x9990+0x0005=0x9995
b= (0x5998)* (0x10) + (0x0015) =0x9980+0x0015=0x9995
Here both huge addresses are representing same physical address. So a==b is true.
[Link], VITAE
Register data type stores in CPU. So it has not any memory address. Hence we cannot write &a.
126. What will be output of following program?
#include<stdio.h>
#include<string.h>
void main(){
char far *p,*q;
printf("%d %d",sizeof(p),sizeof(q));
getch();
}
(A) 2 2
(B) 4 4
(C) 4 2
(D) 2 4
(E) None of above
p is far pointer which size is 4 byte.
By default q is near pointer which size is 2 byte.
Void pointer can hold address of any data type without type casting. Any pointer can hold void
pointer without type casting.
#include<stdio.h>
#include<string.h>
void main(){
int register a;
scanf("%d",&a);
printf("%d",a);
[Link], VITAE
getch();
}
//if a=25
(A) 25
(B) Address
(C) 0
(D) Compilation error
(E) None of above
Register data type stores in CPU. So it has not any memory address. Hence we cannot write &a.
129. What will be output of following program?
#include<stdio.h>
void main(){
char arr[10];
arr = "world";
printf("%s",arr);
getch();
}
(A) world
(B) w
(C) Null
(D) Compilation error
(E) None of above
[Link], VITAE
(A) 2 2 2 2
(B) 1 2 4 8
(C) 1 2 2 4
(D) Compilation error
(E) None of above
[Link], VITAE
(E) None of above
(A) 2
(B) 4
(C) 8
(D) Compilation error
(E) None of above
Output: 2 or 4
since in this question it has not written p is which type of pointer. So its output will depend upon
which memory model has selected. Default memory model is small.
[Link], VITAE
printf(" %u %u", *&p , &*p);
getch();
}
(A) 5 Address
(B) Address Address
(C) Address 5
(D) Compilation error
(E) None of above
Since * and & always cancel to each other.
i.e. *&a = a
so *&p = p which store address of integer i
&*p = &*(&i) //since p = &i
= &(*&i)
= &i
So second output is also address of i
Within the scope of any variable, value of variable may change but its address will never change
in any modification of variable.
137. What will be output of following program?
#include<stdio.h>
void main(){
char far *p =(char far *)0x55550005;
char far *q =(char far *)0x53332225;
*p = 25;
(*p)++;
printf("%d",*q);
getch();
}
(A) 25
[Link], VITAE
(B) Address
(C) Garbage
(D) Compilation error
(E)None of above
Far address of p and q are representing same physical address. Physical address of
0x55550005 = 0x5555 * ox10 + ox0005 = 0x55555
Physical address of
0x53332225 = 0x5333 * 0x10 + ox2225 = 0x55555
*p = 25, means content at memory location 0x55555 is assigning value 25
(*p)++ means to increase the content by one at memory the location 0x5555 so now content of
memory location at 0x55555 is 26
*q also means content at memory location 0x55555 which is 26
(A) 3 Address 3
(B) 3 Address Address
(C) 3 3 3
(D) Compilation error
(E) None of above
[Link], VITAE
}
(A) Network
(B) N
(C) network
(D) Garbage value
(E) Compilation error
}
(A) The African Queen
(B) The
(C) Queen
(D) null
(E) Compilation error
[Link], VITAE
(B) 4.000000
(C) 6.000000
(D) 8.000000
(E) Compilation error
143. What will be output if you will execute following c code?
#include<stdio.h>
enum power{
Dalai,
Vladimir=3,
Barack,
Hillary
};
void main(){
float leader[Dalai+Hillary]={1.f,2.f,3.f,4.f,5.f};
enum power p=Barack;
printf("%0.f",leader[p>>1+1]);
}
(A) 1
(B) 2
(C) 3
(D) 5
(E) Compilation error
[Link], VITAE
printf("%o",data[0][2][1]);
}
(A) 5
(B) 6
(C) 7
(D) 8
(E) Compilation error
[Link], VITAE
}
(A) 6 66 777
(B) 6 77 667
(C) 5 66 777
(D) 7 77 666
(E) 6 67 667
148. What will be output if you will execute following c code?
#include<stdio.h>
void main(){
int array[2][3]={5,10,15,20,25,30};
int (*ptr)[2][3]=&array;
printf("%d\t",***ptr);
printf("%d\t",***(ptr+1));
printf("%d\t",**(*ptr+1));
printf("%d\t",*(*(*ptr+1)+2));
}
(A) 5 Garbage value 20 30
(B) 5 15 20 25
(C) 10 20 30 30
(D) 5 15 20 30
Compilation error
(E)
#include<stdio.h>
void main(){
static int a=2,b=4,c=8;
static int *arr1[2]={&a,&b};
static int *arr2[2]={&b,&c};
int* (*arr[2])[2]={&arr1,&arr2};
printf("%d %d\t",*(*arr[0])[1],*(*(**(arr+1)+1)));
}
(A) 2 4
(B) 4 2
(C) 4 8
(D) 8 4
(E) 8 2
150. What will be output if you will execute following c code?
#include<stdio.h>
#include<math.h>
double myfun(double);
void main(){
[Link], VITAE
double(*array[3])(double);
array[0]=exp;
array[1]=sqrt;
array[2]=myfun;
printf("%.1f\t",(*array)((*array[2])((**(array+1))(4));
}
double myfun(double d){
d-=1;
return d;
}
(A) 1.4
(B) 2.8
(C) 4.2
(D) 3.0
(E) 2.7
[Link] will be output if you will execute following c code?
#include<stdio.h>
#include<math.h>
typedef struct{
char *name;
double salary;
}job;
void main(){
static job a={"TCS",15000.0};
static job b={"IBM",25000.0};
static job c={"Google",35000.0};
int x=5;
job * arr[3]={&a,&b,&c};
printf("%s %f\t",(3,x>>5-4)[*arr]);
}
double myfun(double d){
d-=1;
return d;
}
(A) Google 35000.000000
(B) TCS 15000.000000
(C) IBM 25000.000000
(D) null 15000.000000
(E) Google null
[Link], VITAE
char yarr[4];
};
void main(){
union group x={'A','B','C','D'};
printf("%c",[Link][[Link][2]-67][[Link][3]-67]);
}
(A) A
(B) B
(C) C
(D) D
(E) null
#include<stdio.h>
void main(){
int a=5,b=10,c=15;
int *arr[3]={&a,&b,&c};
printf("%d",*arr[*arr[1]-8]);
}
(A) 5
(B) 10
(C) 18
(D) Garbage value
(E) Compilation error
[Link], VITAE
155. What will be output if you will execute following c code?
#include<stdio.h>
void main(){
int xxx[10]={5};
printf("%d %d",xxx[1],xxx[9]);
}
(A) 0 5
(B) 5 5
(C) 5 0
(D) 0 0
(E) Compilation error
156. What will be output if you will execute following c code?
#include<stdio.h>
#define WWW -1
enum {cat,rat};
void main(){
int Dhoni[]={2,'b',0x3,01001,'\x1d','\111',rat,WWW};
int i;
for(i=0;i<8;i++)
printf(" %d",Dhoni[i]);
}
(A) 2 98 3 513 29 73 0 -1
(B) 2 98 3 513 30 73 1 -1
(C) 2 99 3 513 29 73 1 -1
(D) 2 98 3 513 29 73 1 -1
(E) Compilation error
157. What will be output if you will execute following c code?
#include<stdio.h>
void main(){
long double a;
signed char b;
int arr[sizeof(!a+b)];
printf("%d",sizeof(arr))
}
(A) 8
(B) 9
(C) 1
(D) 4
(E) Compilation error
158.
void main(){
[Link], VITAE
char array[]="Ashfaq \0 Kayani";
char *str="Ashfaq \0 Kayani";
printf("%s %c\n",array,array[2]);
printf("%s %c\n",str,str[2]);
printf("%d %d\n",sizeof(array),sizeof(str));
Ashfaq h
}(A)
Ashfaq h
16 2
(B)
Ashfaq h
Ashfaq Kayani h
16 16
(C)
Ashfaq y
Ashfaq h
22
(D) Compilation error
(E) None of the above
(159)
#include<stdio.h>
#include<conio.h>
void main()
{
int a=5,b=6,c=11;
clrscr();
printf("%d %d %d");
getch();
}
What will output when you compile and run the above code?
(160)
[Link], VITAE
#include<stdio.h>
void main()
{
char *str="CQUESTIONBANK";
clrscr();
printf(str+9);
getch();
}
What will output when you compile and run the above code?
(a)CQESTIONBANK
(b)CQUESTION
(c)BANK
(d)Compiler error
Answer: (c)
(161)
#include<stdio.h>
void main()
{
clrscr();
printf("%d",printf("CQUESTIONBANK"));
getch();
}
What will output when you compile and run the above code?
(a)13CQUESTIONBANK
(b)CQUESTIONBANK13
(c)Garbage CQUESTIONBANK
(d)Compiler error
Answer: (b)
(162)
#include<stdio.h>
#include<conio.h>
void main()
{
short int a=5;
clrscr();
printf("%d"+1,a);
getch();
[Link], VITAE
}
What will output when you compile and run the above code?
(a)6
(b)51
(c)d
(d)Compiler error
Answer: (c)
(163)
#include<stdio.h>
void main()
{
int i=85;
clrscr();
printf("%p %Fp",i,i);
getch();
}
What will output when you compile and run the above code?
(a)85 85
(b)0055 034E:0055
(c)0055 FFFF:0055
(d)Compiler error
Answer: (b)
(164)
#include<stdio.h>
static struct student
{
int a;
int b;
int c;
int d;
}s1={6,7,8,9},s2={4,3,2,1},s3;
void main()
{
s3=s1+s2;
clrscr();
printf("%d %d %d %d",s3.a,s3.b,s3.c,s3.d);
getch();
}
[Link], VITAE
What will output when you compile and run the above code?
(a)6789
(b)4321
(c)10101010
(d)Compiler error
Answer: (d)
(165)
#include<stdio.h>
extern struct student
{
int a;
int b;
int c;
int d;
}s={6,7,8,9};
void main()
{
clrscr();
printf("%d %d %d %d",s.a,s.b,s.c,s.d);
getch();
}
What will output when you compile and run the above code?
(a)6789
(b)9876
(c)0000
(d)Compiler error
Answer: (a)
(166)
#include<stdio.h>
struct student
{
static int a;
register int b;
auto int c;
extern int d;
}s={6,7,8,9};
void main()
{
printf("%d %d % %d",s.a,s.b,s.c,s.d);
}
[Link], VITAE
What will output when you compile and run the above code?
(a)6789
(b)9876
(c)0000
(d)Compiler error
Answer: (d)
(167)
#include<stdio.h>
struct student
{
int roll;
int cgpa;
int sgpa[8];
};
void main()
{
struct student s={12,8,7,2,5,9};
int *ptr;
ptr=(int *)&s;
clrscr();
printf("%d",*(ptr+3));
getch();
}
What will output when you compile and run the above code?
(a)8
(b)7
(c)2
(d)Compiler error
Answer: (c)
(168)
#include<stdio.h>
struct game
{
int level;
int score;
struct player
{
char *name;
}g2={"anil"};
}g3={10,200};
void main()
{
struct game g1=g3;
[Link], VITAE
clrscr();
printf("%d %d %s",[Link],[Link],[Link]);
getch();
}
What will output when you compile and run the above code?
(a)10 200 anil
(b)200 10 anil
(c)10 200 null
(d)Compiler error
Answer: (d)
(169)
#include<stdio.h>
struct game
{
int level;
int score;
struct player
{
char *name;
}g2;
}g1;
void main()
{
clrscr();
printf("%d %d %s",[Link],[Link],[Link]);
getch();
}
What will output when you compile and run the above code?
(a)Garbage_value garbage_value garbage_value
(b)0 0 (null)
(c)Run time error
(d)Compiler error
Answer: (b)
(170) What will be output when you compile and execute the following code?
void main()
{
int i,j;
clrscr();
for(i=0;i<5;i++)
{
for(j=0;j<5;j++)
[Link], VITAE
{
printf("*");
}
printf("\n");
}
getch();
}
(171)What will be output when you compile and execute the following code?
void main()
{
int i,j;
clrscr();
for(i=0;i<8;i++)
{
for(j=0;j<I;J++)< span>
{
printf("*");
}
printf("\n");
}
getch();
}
(172)What will be output when you compile and execute the following code?
void main()
{
int i,j;
clrscr();
for(i=0;i<8;i++)
{
for(j=0;j<=2*i-3;j++)
{
printf("*");
}
printf("\n");
}
getch();
}
(173)What will be output when you compile and execute the following code?
void main()
{
int i,j;
clrscr();
for(i=0;i<6;i++)
[Link], VITAE
{
for(j=0;j<=2*i-2;j++)
{
printf("*");
}
printf("\n");
}
getch();
}
(174)What will be output when you compile and execute the following code?
void main()
{
int i,j;
clrscr();
for(i=0;i<5;i++)
{
for(j=0;j<3*i-2;j++)
{
printf("*");
}
printf("\n");
}
getch();
}
(175)What will be output when you compile and execute the following code?
void main()
{
int i,j;
clrscr();
for(i=0;i<6;i++)
{
for(j=0;j<6-i;j++)
{
printf("*");
}
printf("\n");
}
getch();
}
(176)What will be output when you compile and execute the following code?
void main()
{
int i,j;
[Link], VITAE
clrscr();
for(i=0;i<6;i++)
{
for(j=0;j<8-2*i;j++)
{
printf("*");
}
printf("\n");
}
getch();
}
(177)What will be output when you compile and execute the following code?
void main()
{
int i,j;
clrscr();
for(i=0;i<6;i++)
{
for(j=0;j<=8-2*i;j++)
{
printf("*");
}
printf("\n");
}
getch();
}
(178)What will be output when you compile and execute the following code?
#include"math.h"
void main()
{
int i,j;
clrscr();
for(i=0;i<4;i++)
{
for(j=0;j<2*pow(2,i);j++)
{
printf("*");
}
printf("\n");
}
getch();
}
[Link], VITAE
(179)What will be output when you compile and execute the following code?
#include"math.h"
void main()
{
int i,j;
clrscr();
for(i=0;i<4;i++)
{
for(j=0;j<POW(2,I);J++)< span>
{
printf("*");
}
printf("\n");
}
getch();
}
(180)What will be output when you compile and execute the following code?
#include"math.h"
void main()
{
int i,j;
clrscr();
for(i=0;i<4;i++)
{
for(j=0;j<POW(3,I);J++)< span>
{
printf("*");
}
printf("\n");
}
getch();
}
(181)What will be output when you compile and execute the following code?
#include"math.h"
void main()
{
int i,j;
clrscr();
for(i=0;i<3;i++)
{
for(j=0;j<3*pow(3,i);j++)
{
printf("*");
[Link], VITAE
}
printf("\n");
}
getch();
}
(182)What will be output when you compile and execute the following code?
#include"math.h"
void main()
{
int i,j;
char c='*';
clrscr();
for(i=0;i<5;i++)
{
for(j=0;j<I;J++)< span>
{
printf("%*c",2,c);
}
printf("\n");
}
getch();
}
(183)What will be output when you compile and execute the following code?
#include"math.h"
void main()
{
int i,j;
char * c="*******";
clrscr();
for(i=0;i<5;i++)
{
printf("%*.*s\n",i,i,c);
}
getch();
}
(184)What will be output when you compile and execute the following code?
#include"math.h"
void main()
{
int i,j;
char * c="*******";
clrscr();
for(i=0;i<5;i++)
{
[Link], VITAE
printf("%*.*s\n",i+6,i,c);
}
getch();
}
(185)What will be output when you compile and execute the following code?
void main(){
char *ptr="*******";
int i,j;
clrscr();
for(i=0;i<8;i++){
printf("%*.*s\n",8,i,ptr);
}
getch();
}
(186)What will be output when you compile and execute the following code?
void main(){
char *ptr="*********";
int i,j;
clrscr();
for(i=0;i<5;i++){
Printf ("%*.*s\n",5+i,2*i+1,ptr);
}
getch ();
}
(187)What will be output when you compile and execute the following code?
void main(){
char *ptr="*********";
int i,j;
clrscr();
for(i=0;i<10;i++){
if(i<5)
printf("%*.*s\n",5+i,2*i+1,ptr);
else
printf("%*.*s\n",14-i,19-2*i,ptr);
}
getch();
}
(188)What will be output when you compile and execute the following code?
void main(){
char *ptr="*********";
int i,j;
clrscr();
for(i=0;i<9;i++){
[Link], VITAE
if(i<5)
printf("%*.*s\n",5+i,2*i+1,ptr);
else
printf("%*.*s\n",13-i,17-2*i,ptr);
}
getch();
}
(189)What will be output when you compile and execute the following code?
void main(){
char *ptr="*********";
int i,j;
clrscr();
for(i=0;i<5;i++){
printf("%*.*s\n",9-i,9-2*i,ptr);
}
getch();
}
(190)What will be output when you compile and execute the following code?
void main(){
char *ptr="*****";
int i,j;
clrscr();
for(i=0;i<10;i++){
if(i<6)
printf("%*.*s\n",5,i,ptr);
else
printf("%*.*s\n",5,10-i,ptr);
}
getch();
}
(191)What will be output when you compile and execute the following code?
void main(){
char *ptr="*****";
int i,j;
clrscr();
for(i=1;i<10;i++){
if(i<6)
printf("%*.*s\n",0,i,ptr);
else
printf("%*.*s\n",0,10-i,ptr);
}
getch();
[Link], VITAE
}
(192)What will be output when you compile and execute the following code?
void main(){
char *ptr="*********";
int i,j;
clrscr();
for(i=0;i<11;i++){
if(i<5)
printf("%*.*s\n",5+i,2*i+1,ptr);
else
{
if(i==7)
{
*(ptr+3)=' ';
*(ptr+4)=' ';
*(ptr+5)=' ';
}
printf("%*.*s\n",9,9,ptr);
}
}
getch();
}
(193) What will be output of following c code?
void main()
{
struct employee
{
unsigned id: 8;
unsigned sex:1;
unsigned age:7;
};
struct employee emp1={203,1,23};
clrscr();
printf("%d\t%d\t%d",[Link],[Link],[Link]);
getch();
}
Output: 203 1 23
We can access the data member in same way.
How bit data is stored in the memory:
Minimum size of structure which data member in bit is two byte i.e. 16 bit. This is called word
size of microprocessor. Word size depends on microprocessor. Turbo c is based on 8086
microprocessor which word size is two byte.
[Link], VITAE
Bits are filed in from right to left direction 8 bit for id,1 bit for sex and 7 bit for age.
void main()
{
struct bitfield
{
unsigned a:5;
unsigned c:5;
unsigned b:6;
}bit;
char *p;
struct bitfield *ptr,bit1={1,3,3};
p=&bit1;
p++;
clrscr();
printf("%d",*p);
getch();
}
Output: 12
Explanation:
Binary value of a=1 is 00001 (in 5 bit)
Binary value of b=3 is 00011 (in 5 bit)
Binary value of c=3 is 000011 (in 6 bit)
In memory it is represented as:
Let address of bit1 is 500 which initialize to char pointer p. Since can is one byte data type so
p++ will be 501. *p means content of memory location 501 which is (00001100) and its binary
equivalent is 12. Hence output is 12.
void main()
{
struct bitfield
{
signed int a:3;
unsigned int b:13;
unsigned int c:1;
};
[Link], VITAE
struct bitfield bit1={2,14,1};
clrscr();
printf("%d",sizeof(bit1));
getch();
}
Output: 4
(196) What will be output of following c code?
void main()
{
struct bitfield
{
unsigned a:3;
char b;
unsigned c:5;
int d;
}bit;
clrscr();
printf("%d",sizeof(bit));
getch();
}
Output: 5
Note: (Actual output will 6 due to slack byte ,So Before executing this program first go to option
menu then compiler then code generation then select word alignment then press OK)
Output: 45
Nesting of structure:
[Link], VITAE
Nesting of structure is possible i.e. we can declare a structure within another structure but it is
necessary inner structure must declares structure variable otherwise we can not access the data
member of inner structure.
Example:
void main()
{
struct world
{
int a;
char b;
struct india
{
char c;
float d;
}p;
};
struct world st ={1,'A','i',1.8};
clrscr();
printf("%d\t%c\t%c\t%f",st.a,st.b,st.p.c,st.p.d);
getch();
}
Output: 1 A I 1.800000
void main()
{
struct india
{
char c;
float d;
};
struct world
{
int a[3];
char b;
struct india orissa;
};
struct world st ={{1,2,3},'P','q',1.4};
clrscr();
printf("%d\t%c\t%c\t%f",st.a[1],st.b,[Link].c,[Link].d);
getch();
}
[Link], VITAE
Output: 2 p q 1.400000
199. In the following declaration statement
char c=’A’;
Variable c stores one byte of memory space while character constants ‘A’ stores one byte
memory space. How one byte variables can stores two byte character constant?
200. What is automatic type promotion in c?
201. Swap two variables without using third variable.
202. Write a c program without using any semicolon which output is: Hello word.
203. How will you modify a const variable in c?
204. Write a c program to find out factorial of given number using function recursion.
205. Give an example in which comma is behaving as separator as well as operator in c.
206. What is variable number of arguments in c?
207. What is command line argument?
208. What will be output of following c code?
void main(){
int i;
for(i=0;i<=5;i++);
printf("%d",i);
getch();
}
[Link], VITAE
218. Tell me a all sorting algorithm which you know.
Answer:
1. Character constant reserve two byte of memory space to represent octal or hexadecimal
character constant but char variable stores only its one byte ASCII value.
2. In c if two operands are of different data type in a binary operation then before performing any
operation compiler will automatically convert the operand of lower data type to higher data type
.This phenomenon is known as automatic type conversion. For example:
int a=10,c;
float b=5.5f;
c=a+b;
Here a int variable while b is float variable. So before performing addition operation value of the
variable a (Lower data type) will automatically convert into float constant (higher data type) then
it will perform addition operation.
3.
Solution: 1
void main(){
int x,y;
scanf("%d%d",&x,&y);
//swapping
x=x+y;
y=x-y;
x=x-y;
printf("%d %d",x,y);
}
Solution: 2
void main(){
int x,y;
scanf("%d%d",&x,&y);
//swapping
x=x^y;
y=y^x;
x=x^y;
printf("%d %d",x,y);
}
4.
Solution: 1
void main(){
if(printf("Hello world")){
}
}
Solution: 2
void main(){
[Link], VITAE
while(!printf("Hello world")){
}
}
Solution: 3
void main(){
switch(printf("Hello world")){
}
}
5.
void main(){
const int a=10;
int *ptr=(int *)&a;
*ptr=20;
clrscr();
printf("%d",a);
getch();
}
Output: 20
6.
void main()
{
long num,f;
clrscr();
printf("Input a number: ");
scanf("%ld",&num);
f=fact(num);
printf("\nFactorial is %ld",f);
getch();
}
int fact(long n)
{
if(n==0)
return 1;
else
return(n*fact(n-1));
}
7.
[Link], VITAE
void main(){
int x=5,y=10,z=15,val;
val=sum(x,(y=0,z=0,y),z);
clrscr();
printf("%d",val);
getch();
}
sum(int x,int y,int z){
return x+y+z;
}
Output: 20
Note: In the above program comma in red color are behaving as operator.
8.
A function in which we can pass variables numbers of argument in function call statement such
functions are known as function with variable number of arguments. For example:
void display(int,...);
void main(){
display(1,2);
display(1,2,3,4);
display(1,2,3,4,5,6,7,8,9);
getch();
}
void display(int x,...){
}
10. 6
11.
[Link], VITAE
void main(){
int a,b,d;
scanf("%d%d",&a,&b);
d=a+~b+1;
printf("%d",d);
getch();
}
12.
sizeof is keyword of c which can find size of a string constant including null character but strlen
is function which has been defined string.h and can find number of characters in a string
excluding null character.
#include<string.h>
void main(){
int a,b;
a=strlen("cquestionbank");
b=sizeof("cquestionbank");
printf("%d %d",a,b);
getch();
}
19.
(a) We can easily access each element of array.
(b) Not necessity to declare two many variables.
(c) Array elements are stored in continuous memory location.
Demerit:
(a) Wastage of memory space. We cannot change size of array at the run time.
(b) It can store only similar type of data.
20.
(a)Bubble sort
(b)Selection sort
(c)Insertion sort
(d)Quick sort
(e)Merge sort
(f)Heap sort
219.
What will be output if you will execute following c code?
[Link], VITAE
#include<stdio.h>
int main(){
int a=0;
#if (a==0)
printf("Equal");
#else if
printf("Not equal");
#endif
return 0;
}
(A) Equal
(B) Not equal
(C) null
(D) Garbage
(E) Compilation error
220.
What will be output if you will execute following c code?
#include<stdio.h>
int main(){
for(;NULL;)
printf("cquestionbank");
return 0;
}
(A) c
(B) bank
(C) cquestionbank
(D) Infinite loop
(E) Compilation error
221.
What will be output if you will execute following c code?
#include<stdio.h>
auto int a=5;
int main(){
int x;
x=~a+a&a+a<<a;
printf("%d",x);
return 0;
}
(A)
[Link], VITAE
0
(B) 1
(C) 154
(D) 155
(E) Compilation error
222.
What will be output if you will execute following c code?
#include<stdio.h>
void main(){
int a=5;
{
int b=10;
++b;
++a;
{
int a=20;
++a;
a=++b;
}
++a;
++b;
printf("%d %d",a,b);
}
printf(" %d",a);
}
(A) 7 13 7
(B) 13 13 13
(C) 13 13 5
(D) 6 13 5
(E) Compilation error
223.
What will be output if you will execute following c code?
#include<stdio.h>
#include<conio.h>
void main(){
int a[]={0,1,2,3,4,5,6,7,8,9,10};
int i=0,num;
num=a[++i+a[++i]]+a[++i];
printf("%d",num);
}
[Link], VITAE
(A) 6
(B)
7
(C) 8
(D) 9
(E) Compilation error
224.
What will be output if you will execute following c code?
#include<stdio.h>
#include<conio.h>
void main(){
int i=3,val;
val=sizeof f(i)+ +f(i=1)+ +f(i-1);
printf("%d %d",val,i);
}
int f(int num){
return num*5;
}
(A) 2 0
(B) 7 1
(C) 17 0
(D) 2 1
(E) Compilation error
225.
What will be output if you will execute following c code?
#include<stdio.h>
#include<conio.h>
void main(){
int i;
(i=8)+=1;
printf("%d",i);
}
(A) 9
(B) 10
(C) 32
(D) 34
(E) Compilation error
226.
[Link], VITAE
What will be output if you will execute following c code?
#include<stdio.h>
#include<conio.h>
void main(){
char c=-'a';
printf("%d",c);
}
(A) 65
(B) -65
(C) -a
(D) -97
(E) Compilation error
227.
What will be output if you will execute following c code?
#include<stdio.h>
#include<conio.h>
void main(){
int num,a=5;
num=-a--;
printf("%d %d",num,a);
}
(A) 5 4
(B) -4 4
(C) -5 4
(D) -4 5
(E) Compilation error
228.
What will be output if you will execute following c code?
#include<stdio.h>
#include<conio.h>
void main(){
int num,a=10;
num=a&&0+ +-1&&a;
printf("%d %d",num,a);
}
(A) 1 1
(B) 0 0
[Link], VITAE
(C) 1 10
(D) 0 10
(E) Compilation error
229.
What will be output if you will execute following c code?
#include<stdio.h>
#include<conio.h>
void main(){
int x,y,z;
y=(x=1,y=2,z=3);
printf("%d %d %d",x,y,z);
}
(A) 1 2 3
(B) 1 1 3
(C) 1 3 3
(D) 1 0 3
(E) Compilation error
230.
What will be output if you will execute following c code?
#include<stdio.h>
#include<conio.h>
void main(){
int t,a=5,b=10,c=15;
t=(++a&&++b,++a),++a||++c;
printf("%d %d %d %d",t,a,b,c);
}
(A) 7 8 11 15
(B) 6 7 10 14
(C) 1 8 10 15
(D) 6 18 11 15
(E) Compilation error
231.
What will be output if you will execute following c code?
#include<stdio.h>
#include<conio.h>
int a=5;
void main(){
int x;
[Link], VITAE
x=!a+change();
printf("%d",x);
}
int change(){
a=0;
return 0;
}
(A) 0
(B) 5.000000
(C) 0.000000
(D) 1.000000
(E) Compilation error
232.
What will be output if you will execute following c code?
#include<stdio.h>
typedef struct cquestionbank{
int num;
struct cquestionbank **p;
struct cquestionbank ***q;
}cqb;
int main(){
static cqb *var1,**var2;
cqb temp={5,&var1,&var2};
var2=&var1;
var1->num=25;
printf("%d %d ",**(temp.q),***(temp.q));
return 0;
}
(A) 0 5
(B) 0 25
(C) 5 25
(D) 25 5
(E) Compilation error
233.
What will be output if you will execute following c code?
#include<stdio.h>
union cqbu{
int a;
char b;
};
[Link], VITAE
struct cqbs{
int a;
char b;
};
int main(){
union cqbu u={25};
struct cqbs *ps=(struct cqbs *)&u;
union cqbu *pu=(union cqbu *)&u;
printf("%d %d\n",ps->a,ps->b);
printf("%d %d\n",pu->a,pu->b);
return 0;
}
(A) 25 0
25 25
(B) 25 25
25 0
(C) 0 0
25 25
(D) 25 25
25 25
(E) Compilation error
234.
What will be output if you will execute following c code?
int main(){
float x;
x=(float)3.5==3.5;
printf("%f",x);
return 0;
}
(A) 0
(B) 0.000000
(C) 1.000000
(D) 3.000000
(E) Compilation error
235.
What will be output if you will execute following c code?
[Link], VITAE
int main(){
float x;
x=(int)(int)2.5+5.8f;
printf("%f",x);
return 0;
}
(A) 7.000000
(B) 7.800000
(C) 8.000000
(D) 8.100000
(E) Compilation error
236.
What will be output if you will execute following c code?
int main(){
float x;
x=(float)3.3==3.3;
printf("%f",x);
return 0;
}
(A) 0.000000
(B) 1.000000
(C) 3.000000
(D) 3.300000
(E) Compilation error
237.
code?
#include "string.h"
typedef struct stu1{
int roll;
char *name;
double marks;
}STU1;
typedef struct stu2{
int roll;
char *name;
double marks;
}STU2;
void main(){
[Link], VITAE
STU1 s1={25,"Rohit",87.43},*p1;
static STU2 *p2;
p1=&s1;
memccpy(p2,p1,'\0',sizeof(STU1));
printf("Roll : %d\n",p2->roll);
printf("Name : %s\n",p2->name);
printf("Marks : %lf",p2->marks);
}
Roll : 25
(A)
Name : (null)
Marks : 0.000000
Roll : 25
(B)
Name : rohit
Marks : 0.000000
Roll : 25
(C)
Name : rohit
Marks : 87.430000
Roll : 0
(D)
Name : (null)
Marks : 0.000000
(E) Compilation error
238.
What will be output if you will execute following c code?
#include<stdio.h>
#define value 30
int main(){
#if max
printf("Defined");
#else
printf("Not defined");
#endif
return 0;
}
(A) Defined
(B) Not defined
(C) null
(D) Run time error
[Link], VITAE
(E) Compilation error
239.
What will be output of following c program?
#include<stdio.h>
#define max
int main(){
printf("%d",max);
return 0;
}
(A) 0
(B) null
(C) Garbage
(D) -1
(E) Compilation error
240.
What will be output of following c program?
#include<stdio.h>
int main(){
for(printf("1");!printf("0");printf("2"))
printf("Sachin");
return 0;
}
(A) 10sachin2
(B) 10sachin
(C) 10sachin210sachin2
(D) 10
(E) Compilation error
241.
What will be output of following c program?
#include<stdio.h>
int main(){
int a=5;
static int b=a;
printf("%d %d",a,b);
return 0;
}
(A) 5 5
[Link], VITAE
(B) 5 0
(C) 5 null
(D) 5 Garbage
(E) Compilation error
242.
What will be output of following c program?
#include<stdio.h>
void main(){
int i;
for(i=0;i<5;i++){
int x=0;
printf("%d",x);
x++;
}
}
(A) 01234
(B) 001234
(C) 0000
(D) Infinite loop
(E) Compilation error
243.
What will be output of following c program?
#include<stdio.h>
#include<conio.h>
void main(){
int a[]={5,10,15};
int i=0,num;
num=a[++i]+ ++i+(++i);
printf("%d",num);
}
(A) 6
(B) 17
(C) 16
(D) 12
(E) Compilation error
244.
What will be output of following c program?
#include<stdio.h>
#include<conio.h>
[Link], VITAE
void main(){
int i=3,val;
val=f(i)+ +f(i=1)+ +f(i-1);
printf("%d",val);
}
int f(int num){
return num*5;
}
(A) 30
(B) 20
(C) 21
(D) 31
(E) Compilation error
245.
What will be output of following c program?
#include<stdio.h>
#include<conio.h>
long fu(int);
char vect[]={1,2,3,4,5};
void main(){
int i=1;
i=fu(++i)+ ++vect[++i]+ ++i+fu(i++);
printf("%d",i);
}
long fu(int x){
return x*3;
}
(A) 31
(B) 32
(C) 33
(D) 34
(E) Compilation error
246.
What will be output of following c program?
#include<stdio.h>
#include<conio.h>
void main(){
int a,i=4;
a=- -i+- -i+- -5;
printf("%d %d",a,i);
[Link], VITAE
}
(A) 13 4
(B) -3 2
(C) 7 2
(D) -13 4
(E) Compilation error
247.
What will be output of following c program?
#include<stdio.h>
#include<conio.h>
void main(){
int num,a=5;
num=---a;
printf("%d %d",num,a);
}
(A) -4 4
(B) 3 3
(C) -4 5
(D) -5 -5
(E) Compilation error
248.
What will be output of following c program?
#include<stdio.h>
#include<conio.h>
void main(){
int num,a=10;
num=a--- -a--;
printf("%d %d",num,a);
}
(A) 0 8
(B) 0 10
(C) 20 8
(D) -1 10
(E) Compilation error
249.
What will be output of following c program?
#include<stdio.h>
#include<conio.h>
[Link], VITAE
void main(){
int z;
z=(5,3,2);
printf("%d",z);
}
(A) 5
(B)
3
(C) 2
(D) 10
(E) Compilation error
250.
What will be output of following c program?
#include<stdio.h>
#include<conio.h>
void main(){
int i=5,j=10,num;
num=(++i,++j,i+j);
printf("%d %d %d",num,i,j);
}
(A) 17 6 11
(B) 6 6 11
(C) 15 6 11
(D) 15 5 10
(E) Compilation error
251.
What will be output of following c program?
#include<stdio.h>
#include<conio.h>
float avg(float,float,float);
void main(){
float p=1,q=2,r=-2,a;
a=avg(p,(q=4,r=-12,q),r);
printf("%f",a);
}
float avg(float x,float y,float z){
return (x+y+z)/3;
}
(A) 0.111111
(B) 1.000000
[Link], VITAE
(C) -0.777777
(D) -1.000000
(E) Compilation error
252.
What will be output of following c program?
#include<stdio.h>
int main(){
float **(*ptr)[4]=(float **(*)[4])0;
ptr+=5;
printf("%d %d",ptr,sizeof ptr);
return 0;
}
(A) 0 2
(B) 5 2
(C) 4 2
(D) 40 2
(E) Compilation error
253.
What will be output of following c program?
#include<stdio.h>
struct myStruct{
int a;
char b;
}*ptr;
int main(){
struct myStruct ms={400,'A'};
printf("%d %d",ptr->a,ptr->b);
return 0;
}
(A) 400 A
(B) 400 65
(C) 400 97
(D) 0 0
(E) Compilation error
254.
What will be output of following c program?
[Link], VITAE
#include<stdio.h>
int main(){
float x;
x=(int)5.6f*3.2f/sizeof((int)6.6);
printf("%f",x);
return 0;
}
(A) 8.960000
(B) 9.600000
(C) 8.000000
(D) 2.000000
(E) Compilation error
255.
What will be output of following c program?
#include<stdio.h>
#define plus +
#define minus +plus
int main(){
long x,i=3;
x=+ + i;
printf("%ld",x);
return 0;
}
(A) 4
(B) 3
(C) 0
(D) 6
(E) Compilation error
256.
What will be output of following c program?
#include<stdio.h>
int main(){
float x;
x=(int)1.1,(float)2.2,(int)3.3 ,5.4;
printf("%f",x);
return 0;
}
(A) 1.000000
(B) 5.400000
[Link], VITAE
(C) 2.200000
(D) 3.300000
(E) Compilation error
257.
What will be output of following c program?
#include<stdio.h>
#include "string.h"
typedef struct stu1{
int roll;
char *name;
double marks;
}STU1;
typedef struct stu2{
int roll;
char *name;
double marks;
}STU2;
void main(){
STU1 s1={25,"Rohit",87.43},*p1;
STU2 *p2;
p1=&s1;
memcpy(p2,p1,4);
printf("Roll : %d\n",p2->roll);
printf("Name : %s\n",p2->name);
printf("Marks : %lf",p2->marks);
}
Roll : 25
(A)
Name : Rohit
Marks : 87.430000
Roll : 25
(B)
Name : Rohit
Marks : 0.000000
Roll : 0
(C)
Name : Rohit
Marks : 87.430000
Roll : 0
(D)
Name : null
Marks : 0.000000
(E) Compilation error
[Link], VITAE
258.
What will be output of following c program?
#include "string.h"
typedef struct stu1{
char name1[6];
char name2[6];
double marks;
}STU1;
void main(){
STU1 s1={"rohit","kumar",87.43},*p1;
char *p;
p1=&s1;
p=memchr(p1,'u',sizeof(STU1));
printf("%s",p);
}
(A) r
(B) rohit
(C) umar
(D) rohit kumar
(E) Compilation error
INTRODUCTION:
Every programming language deals with some data. For example to print any message it
requires charterer or string type of data. To solve any mathematic expression it requires integral
as well as real number (floating type) of data. C is very rich in data type. We can broadly divide
all data type in c in three categories:
1. Primitive or fundamental data type
2. Derived data type
3. User defined data type
A complete picture of all c data types has been represented by following figure.
[Link], VITAE
Note: Apart from these basic data type there are few other data types which have been defined
inside header files which will be discussed later.
Primitive or most fundamental data type in c can be categorized in three groups on the basis of
its application:
[Link], VITAE