C Test
C Test
--------------------------------------------------------------------
175
#define swap1(a,b) a=a+b;b=a-b;a=a-b;
main()
{
int x=5,y=10;
swap1(x,y);
printf("%d %d\n",x,y);
swap2(x,y);
printf("%d %d\n",x,y);
}
int swap2(int a,int b)
{
int temp;
temp=a;
b=a;
a=temp;
return;
}
----------------------------------------------------------------------
176
main()
{
char *ptr = "Ramco Systems";
(*ptr)++;
printf("%s\n",ptr);
ptr++;
printf("%s\n",ptr);
}
Samco systems, amco systems
---------------------------------------------------------------------
178
#include<stdio.h>
main()
{
char s1[]="Ramco";
char s2[]="Systems";
s1=s2;
printf("%s",s1);
}
-----------------------------------------------------------------
179
#include<stdio.h>
main()
{
char *p1;
char *p2;
p1=(char *) malloc(25);
p2=(char *) malloc(25);
strcpy(p1,"Ramco");
strcpy(p2,"Systems");
strcat(p1,p2);
printf("%s",p1);
}
l: Before using the ptr type struct variable we have to give memory to that .
And also when ever the struct variable is ptr then we access the members
by "->" operator.
186.o/p=?
int i;
i=1;
i=i+2*i++;
printf(%d,i);
ans: 4
188.#include<malloc.h>
char *f()
{char *s=malloc(8);
strcpy(s,"goodbye")}
main()
{
char *f();
printf("%c",*f()='A');
o/p=?
: .............................................
191. what is o/p
#include<stdarg.h>
show(int t,va_list ptr1)
{
int a,x,i;
a=va_arg(ptr1,int)
printf("\n %d",a)
}
display(char)
{int x;
listptr;
va_star(otr,s);
n=va_arg(ptr,int);
show(x,ptr);
}
main()
{
display("hello",4,12,13,14,44);
}
a) 13 b) 12 c) 44 d) 14
.............................................
192.main()
{
int i = 10;
printf(" %d %d %d \n", ++i, i++, ++i);
}
193.#include<stdio.h>
main()
{
int *p, *c, i;
i = 5;
p = (int*) (malloc(sizeof(i)));
printf("\n%d",*p);
*p = 10;
printf("\n%d %d",i,*p);
c = (int*) calloc(2);
printf("\n%d\n",*c);
}
195.#include <stdio.h> main() { enum _tag{ left=10, right, front=100, back}; printf("left is %d, right
is %d, front is %d, back is %d",left,right,front,back); }
196.main()
{
int a=10,b=20;
a>=5?(b=100):(b=200);
printf("%d\n",b);
}
#include<stdio.h>
main()
{
int a[] ={ 1,2,3,4,5,6,7};
char c[] = {' a','x','h','o','k'};
printf("%d\t %d ", (&a[3]-&a[0]),(&c[3]-&c[0]));
}
ans : 12 3
#include<stdio.h>
main()
{
struct s1 {int i; };
struct s2 {int i; };
struct s1 st1;
struct s2 st2;
st1.i =5;
st2 = st1;
printf(" %d " , st2.i);
}
ans: error
expl: diff struct variables should not assigned using "=" operator.
201.what is the output of the program?
#include<stdio.h>
main()
{
int i,j;
int mat[3][3] ={1,2,3,4,5,6,7,8,9};
for (i=2;i>=0;i--)
for ( j=2;j>=0;j--)
printf("%d" , *(*(mat+j)+i));
}
ans : 9 6 3 8 5 2 7 4 1
202
fun(n);
}
int fun( int n)
{
int i;
for(i=0;i<=n;i++)
fun(n-i);
printf(" well done");
}
howmany times is the printf statement executed for n=10?
ans: zero
expl: Befire reaching to printf statement it will goes to infinite loop.
main()
{
struct emp{
char emp[];
int empno;
float sal;
};
struct emp member = { "TIGER"};
printf(" %d %f", member.empno,member.sal);
ans: none
expl: infiniteloop in main ends with ";" . so loop will not reach end;
and the DONE also will not print.
main()
{
int a=2, b=3;
printf(" %d ", a+++b);
}
ans:5
expl: here it evaluates as a++ + b.
main()
{
int x=1, y=2;
print(max(x++,y),x,y);
print(max(x++,y),x,y);
}
ans: 3 4 2
207. which of the following is the correct declaration for the function main() ?
int *ptr[][100];
which of the following correctly allocates memory for ptr?
214.o/p=?
int i;
i=1;
i=i+2*i++;
printf(%d,i);
215.{ ch='A';
while(ch<='F'){
switch(ch){
case'A':case'B':case'C':case'D':ch++;continue;
case'E':case'F':ch++;
}
putchar(ch);
}
}
a)ABCDEF b.EFG c.FG d.error
a.error b. c. d.
218.#include<malloc.h>
char *f()
{
char *s=malloc(8);
strcpy(s,"goodbye")
}
main()
{
char *f()_;
printf("%c",*f()='A');
}
o/p=?
: .............................................
223 what is o/p
#include<stdarg.h>
show(int t,va_list ptr1)
{
int a,x,i;
a=va_arg(ptr1,int)
printf("\n %d",a)
}
display(char)
{int x;
listptr;
va_star(otr,s);
n=va_arg(ptr,int);
show(x,ptr);
}
main()
{
display("hello",4,12,13,14,44);
}
a) 13 b) 12 c) 44 d) 14
.............................................
225.what is o/p
main()
{int i=3;
while(i--)
{
int i=100
i--;
printf("%d..",i);
}
}
a) infinite loop
b) error
c) 99..99..99..99
d) 3..22..1..
.............................................
226)what is the o/p of the program
main()
{
int rows=3,colums=4;
int a[rows][colums]={1,2,3,4,5,6,7,8,9,10,11,12};
i=j=k=99;
for(i=0;i<rows;i++)
for(j=0;j<colums;j++)
if(a[k][j]<k) k=a[i][j];
printf("%d\n",k);
ANS: UNDEFINED
231.
VOID MAIN()
{
INT I;
FOR(I=1;I<4,I++)
SWITCH(I)
CASE 1: PRINTF("%D",I);BREAK;
{
CASE 2:PRINTF("%D",I);BREAK;
CASE 3:PRINTF("%D",I);BREAK;
}
SWITCH(I) CASE 4:PRINTF("%D",I);
}
ANS: 1,2,3,4
232.
VOID MAIN()
{
CHAR *S="\12345S\N";
PRINTF("%D",SIZEOF(S));
}
ANS: 6
233
VOID MAIN()
{
UNSIGNED I=1; /* UNSIGNED CHAR K= -1 => K=255; */
SIGNED J=-1; /* CHAR K= -1 => K=65535 */
/* UNSIGNED OR SIGNED INT K= -1 =>K=65535 */
IF(I<J)
PRINTF("LESS");
ELSE
IF(I>J)
PRINTF("GREATER");
ELSE
IF(I==J)
PRINTF("EQUAL");
}
ANS: LESS
234
VOID MAIN()
{
FLOAT J;
J=1000*1000;
PRINTF("%F",J);
}
1. 1000000
2. OVERFLOW
3. ERROR
4. NONE
ANS: 4
235.
INT F()
VOID MAIN()
{
F(1);
F(1,2);
F(1,2,3);
}
F(INT I,INT J,INT K)
{
PRINTF("%D %D %D",I,J,K);
}
ANS: NONE.
236.
VOID MAIN()
{
INT I=7;
PRINTF("%D",I++*I++);
}
ANS: 56
237.
#DEFINE ONE 0
#IFDEF ONE
PRINTF("ONE IS DEFINED ");
#IFNDEF ONE
PRINTF("ONE IS NOT DEFINED ");
ANS: 20 20 20
239.
MAIN()
{
STATIC I=3;
PRINTF("%D",I--);
RETURN I>0 ? MAIN():0;
}
ANS: 321
240.
CHAR *FOO()
{
CHAR RESULT[100]);
STRCPY(RESULT,"ANYTHING IS GOOD");
RETURN(RESULT);
}
VOID MAIN()
{
CHAR *J;
J=FOO()
PRINTF("%S",J);
}
(A) 4
( B) 5
(C) 6
(D) 11
(E) NONE OF THE ABOVE
243. FIND THE OUTPUT FOR THE FOLLOWING C PROGRAM
MAIN
{INT X,J,K;
J=K=6;X=2;
X=J*K;
PRINTF("%D", X);
I=20,K=0;
FOR(J=1;J<I;J=1+4*(I/J))
{K+=J<10?4:3;
}
PRINTF("%D", K);
ANS. K=4
246. FIND THE OUTPUT FOR THE FOLLOWING C PROGRAM
INT I =10
MAIN()
{INT I =20,N;
FOR(N=0;N<=I;)
{INT I=10;
I++;
}
PRINTF("%D", I);
ANS. I=20
INT X=5;
Y= X&Y
Y=10;
IF( Y++>9 && Y++!=10 && Y++>10)
{PRINTF("%D", Y);
ELSE
PRINTF("%D", Y);
}
ANS. 13
F=(X>Y)?X:Y
ANS. (A)
(A) 4 BYTES
(B) 2 BYTES
(C) COMPILER DEPENDENT
(D) 8 BYTES
251. WHICH OF THE FUNCTION OPERATOR CANNOT BE OVER LOADED
(A) <=
(B) ?:
(C) ==
(D) *
252. FIND THE OUTPUT FOR THE FOLLOWING C PROGRAM
MAIN()
{INT X=2,Y=6,Z=6;
X=Y==Z;
PRINTF(%D",X)
}
(C) BOTH E & F
(D) B
(E) BOTH B & C
ANS. (B)
253 main()
{
int x=10,y=15;
x=x++;
y=++y;
printf("%d %d\n",x,y);
}
254 int x;
main()
{
int x=0;
{
int x=10;
x++;
change_value(x);
x++;
Modify_value();
printf("First output: %d\n",x);
}
x++;
change_value(x);
printf("Second Output : %d\n",x);
Modify_value();
printf("Third Output : %d\n",x);
}
Modify_value()
{
return (x+=10);
}
change_value()
{
return(x+=1);
}
255 main()
{
int x=20,y=35;
x = y++ + x++;
y = ++y + ++x;
printf("%d %d\n",x,y);
}
256 main()
{
char *p1="Name";
char *p2;
p2=(char *)malloc(20);
while(*p2++=*p1++);
printf("%s\n",p2);
}
257 main()
{
int x=5;
printf("%d %d %d\n",x,x<<2,x>>2);
}
258 #define swap1(a,b) a=a+b;b=a-b;a=a-b;
main()
{
int x=5,y=10;
swap1(x,y);
printf("%d %d\n",x,y);
swap2(x,y);
printf("%d %d\n",x,y);
}
261 #include<stdio.h>
main()
{
char s1[]="Ramco";
char s2[]="Systems";
s1=s2;
printf("%s",s1);
}
262 #include<stdio.h>
main()
{
char *p1;
char *p2;
p1=(char *) malloc(25);
p2=(char *) malloc(25);
strcpy(p1,"Ramco");
strcpy(p2,"Systems");
strcat(p1,p2);
printf("%s",p1);
}
263 )
main()
{
char a[2];
*a[0]=7;
*a[1]=5;
printf("%d",&a[1]-a)
ANS:
(ans is hellow,hellow,hellow
6,2,5 )
265)
#include<stdio.h>
main()
float value=10.00;
printf("%g %0.2g %0.4g %f",value,value,value,value)
}
(ans is 10,10,10,10.000000)
266)
#include<stdio.h>
void function1;
int i-value=100;
main()
{
i-value=50;
function1;
printf("i-value in the function=",i-value);
printf("i-value after the function=",i-value);
}
printf("i-value at the end of main=",i-value);
functioni()
i-value=25;
THIS IS ROUGH IDEA OF THE PROGRAM
ANS ARE
1)i-value in the function=25;
2)i-value after the function=50;
3)i-value at the end of the main=100;
267)
main()
{
funct(int n);
{
switch(n)
case1:
m=2;
break;
case2:
m=5;
break;
case3:
m=7;
break;
default:
m=0;
}
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,22
D) 16,21
E) SYNTAX ERROR
ANS. (D)
MAIN()
{CHAR C=-64;
INT I=-32
UNSIGNED INT U =-16;
IF(C>I)
{PRINTF("PASS1,");
IF(C<U)
PRINTF("PASS2");
ELSE
PRINTF("FAIL2");
}
ELSE
PRINTF("FAIL1);
IF(I<U)
PRINTF("PASS2");
ELSE
PRINTF("FAIL2")
}
A) PASS1,PASS2
B) PASS1,FAIL2
C) FAIL1,PASS2
D) FAIL1,FAIL2
E) NONE OF THESE
ANS. (C)
270. WHAT WILL THE FOLLOWING PROGRAM DO?
VOID MAIN()
{
INT I;
CHAR A[]="STRING";
CHAR *P="NEW SRING";
CHAR *TEMP;
TEMP=A;
A=MALLOC(STRLEN(P) + 1);
STRCPY(A,P); //LINE NUMBER:9//
P = MALLOC(STRLEN(TEMP) + 1);
STRCPY(P,TEMP);
PRINTF("(%S, %S)",A,P);
FREE(P);
FREE(A);
} //LINE NUMBER 15//
ANS. (B)
271. WHAT WILL BE THE RESULT OF THE FOLLOWING PROGRAM ?
CHAR *GXXX()
{STATIC CHAR XXX[1024];
RETURN XXX;
}
MAIN()
{CHAR *G="STRING";
STRCPY(GXXX(),G);
G = GXXX();
STRCPY(G,"OLDSTRING");
PRINTF("THE STRING IS : %S",GXXX());
}
ANS. (B)
MAIN()
{CHAR *G="STRING";
MYALLOC(G,20);
STRCPY(G,"OLDSTRING");
PRINTF("THE STRING IS %S",G);
}
MAIN()
{CHAR P[]="STRING";
INT X=0;
IF(P=="STRING")
{PRINTF("PASS 1");
IF(P[SIZEOF(P)-2]=='G')
PRINTF("PASS 2");
ELSE
PRINTF("FAIL 2");
}
ELSE
{
PRINTF("FAIL 1");
IF(P[SIZEOF(P)-2]=='G')
PRINTF("PASS 2");
ELSE
PRINTF("FAIL 2");
}
}
A) PASS 1, PASS 2
B) FAIL 1, FAIL 2
C) PASS 1, FAIL 2
D) FAIL 1, PASS 2
E) SYNTAX ERROR DURING COMPILATION
274. WHICH OF THE CHOICES IS TRUE FOR THE MENTIONED DECLARATION ?
ANS. (B)
276. THE COMMAND GREP FIRST SECOND THIRD /USR/YOU/MYFILE
A) PRINTS LINES CONTAINING THE WORDS FIRST, SECOND OR THIRD FROM THE FILE /USR/YOU/MYFILE
B) SEARCHES FOR LINES CONTAINING THE PATTERN FIRST IN THE FILES
SECOND, THIRD, AND /USR/YOU/MYFILE AND PRINTS THEM
C) SEARCHES THE FILES /USR/YOU/MYFIEL AND THIRD FOR LINES CONTAINING THE WORDS FIRST OR SECOND AND PRINTS
THEM
D) REPLACES THE WORD FIRST WITH THE WORD SECOND IN THE FILES THIRD AND /USR/YOU/MYFILE
E) NONE OF THE ABOVE
ANS. (B)
277. Find the output for the following C program
int array[4][4] = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16};
for (i=2;i<0;i--)
for (j=2;j<=0;j--)
printf(“%d”, arr[i][j]);
278. Find the output for the following C program
#include<stdio.h>
void main()
{int i,x,sum=0;
int arr[6]=[1,2,3,4,5,6]
for (i=0;i<4;i++)
sum+ = func(arr[i]);
printf(“%d”, sum);
}
func(int x)
{ int val,x;
val = 2;
return(x+ val++);
}
279. For the following C progralm
int d=0;
for(int i=0;i<31;i++)
for(int j=0;j<31;j++)
for(int k=0;k<31;k++)
if (((i+j+k) % 3)==0)
d=d+1;
Find value of d
f()
{
int a;
void c;
f2(&c,&a);}
292 a=0;
b=(a=0)?2:3;
Choice :
a) Both are identical
b) The first is a correct declaration and the second
is wrong
c) The first declaraion is a function returning a
pointer to an integer and the
second is a pointer to function returning int
d) Both are different ways of declarin pointer to a
function
Answer : c
main()
{
int x=7;
int y=3;
dprintf(x/y);
}
Choice:
a) #2 = 2 b) expr=2 c) x/y=2 d) none
Answer: c
main()
{
char *c;
int *p;
c =(char *)malloc(100);
ip=(int *)c;
free(ip);
}
main()
{
int i;
char *p;
i=0X89;
p=(char *)i;
p++;
printf("%x\n",p);
}
ans:0X8A
choice:
a) The function can change values in the original
array
b) In C parameters are passed by value. The funciton
cannot change the original
value in the array
c) It results in compilation error when the function
tries to access the
elements in the array
d) Results in a run time error when the funtion tries
to access the elements in
the array
Answer: a
Answer : d
302.What is the value of the statement (3^6) + (a^a)?
a) 3 b) 5 c) 6 d) a+18 e) None
Answer : b
a) 7 b) 28 c) 3 d) 14 e) None
ans: c
Answer : b
if(a=3)
b++;
printf("%d %d\n",a,b++);
}
Answer : d
Answer: b
Answer: may be d
main()
{
int l=6;
switch(l)
{ default : l+=2;
case 4: l=4;
case 5: l++;
break;
}
printf("%d",l);
}
a)8 b)6 c)5 d)4 e)none
Answer : c
Answer:d
Answer : d
struct Node {
char *word;
int count;
struct Node left;
struct Node right;
}
a) Incorrect definition
b) structures cannot refer to other structure
c) Structures can refer to themselves. Hence the
statement is OK
d) Structures can refer to maximum of one other
structure
Answer :c
may be b
a)Hello,.World...
b)....Hello,.Wor
c)Hello,.Wor....
d)None of the above
may be c
315) Consider the following function written in c:
#define NULL 0
char *
index(sp,c)
register char *sp,c;
{
do {
if(*sp == c)
return (sp);
} while (*sp++);
return NULL;
}
The first argument sp, is a pointer to a C string. The second argument, c, is a character. This function
searches for the character c, in the string. If it is found a pointer to that location is returned else NULL is
returned.
This function works
a) Always
b) Always, but fails when the first byte contains the character c
c) works when c is a non NULL character only
d) Works only when the character c is found in the string
answer: a
a) 4
b) 5
c) 6
d) 7
answer: a
a) 1 and 1 is printed
b) 1 and 4 is printed
c) 4 and 4 is printed
d) causes an exception
main()
{
int i=20,*j=&i;
f1(j);
*j+=10;
f2(j);
printf("%d and %d",i,*j);
}
f1(k)
int *k;
{
*k +=15;
}
f2(x)
int *x;
{
int m=*x,*n=&m;
*n += 10;
}
int
func (int x)
{
if (x<=0)
return(1);
return func(x -1) +x;
}
main()
{
printf("%d\n",func(5));
}
a) 12
b) 16
c) 15
d) 11
321) Consider the following of c code in two files which will be linked together and executed .
a.c
___
int i;
main()
{
i = 30;
f1();
printf("%d\n",i)
}
b.c
___
static int f1()
{
i+=10;
}
answer: e
answer: d
323. Given the following statement
enum day = { jan = 1 ,feb=4, april, may}
What is the value of may?
(a) 4
(b) 5
(c) 6
(d) 11
(e) None of the above
337)
void main()
{
int x=8;
clrscr();
x = x > 10 ? x<<2 : x>7 ? x>>2 : x<<3;
printf("%d",x);
}
a) 1 b) 2 c) 4 d) None ans : b
339)
f(int x)
{
if(x<=0) return 1;
return f(x-1) + x;
}
void main()
{
printf("%d",f(7));
}
a) 28 b) 29 c) 15 d) None ans : b
342)
#define NULL 0
char * f(str,c)
register char * str,c;
{
while(*str)
if(*str++ == c) return str;
return NULL;
}
a) the above function will always work
b) won't work for c = NULL c) won't work if c is not found
d) won't work if c is the first character ans : a
343)
void main()
{
int x = 10, y=6,z=4;
x=y==z;
printf("%d",x);
}
a) 0 b) 1 c)6 d) compiler Error e) None of the above ans : a
b.c
---
static void f1()
{
i += 15;
}
a) a.c won't compile as f1() is not declered
b) b.c won't compile as i is not declered
c) prints 25 d) prints 10 ans : a
346)
void f(int *x,int y)
{
int temp;
temp = *x;
*x = y;
y = temp;
}
void f1(int *x)
{
int *a,b;
b = *x;
a = &b;
*a += 10;
}
void main()
{
int a =10,b=5;
int *c;
c = &a;
f(c,b);
f1(c);
printf("%d %d",a,b);
}
a) 5 5 b)10 5 c)15 10 d)None ans : a
347)
void f(int *x)
{
*x += 10;
}
void f1(int *y)
{
int temp,*pt;
temp = *y;
pt = &temp;
*pt += 15;
}
void main()
{
int x = 10;
f(&x);
f1(&x);
printf("%d",x);
}
a)35 a)25 c)20 d)10 ans : c
348) expression in switch statement can not accept the data type
a) int b) char c) short d) float ans : d
350)
f(int a,int b)
{
if(a<b) return &a;
return &b;
}
void main()
{
int a=10,b=5,*c;
c = f(b,a);
printf("%d",*c);
}
a) compile error b) 10 c) 5 d) Junk ans : c
354.main
{
int x,j,k;
j=k=6;x=2; ans x=1
x=j*k;
printf("%d", x);
355. fn f(x)
{ if(x<=0)
return; ans fn(5) ....?
else f(x-1)+x;
}
356. i=20,k=0;
for(j=1;j<i;j=1+4*(i/j))
{
k+=j<10?4:3;
}
.main() {
printf("%d",printf("HelloSoft"));
} Output?
357.case 1: case 2:
typedef Struct { typedef Struct {
int a; char p;
char b; int q;
int d; char k;
char e; int l;
}A; }A;
Assuming 'packing' is not enabled, which case will give an
error of Sizeof(A) less.
358.main() {
int i=3;
printf("%d %d %d",i++,i,++i);
}
359.main() {
int i=10;
int j,k=5;
int a[10];
for(j=0;j<10;j++)
a[j]=(i+k)+(i*k);
}
Optimize the above code.
360 .main() {
int *p=0x100;
int *q=0x100;
int k=p*q;
printf("%x\n",k);
} Output ?
361.Char* foo(Str...) {
char str[4];
strcpy(str,"HelloSoft");
return str;
} Output?
363.main() {
int i=10;
if(i>20)
if(i==10)
print("Hi");
else
printf("Bye");
} Output ?
364.main() {
float f;
int i;
//something like this i do not remember these 4 questions
exactly
f=(float *)malloc(sizeof((float *)*4));
}
Some Question was asked i do not remenber .
369. f=(x>y)?x:y
a) f points to max of x and y
b) f points to min of x and y
c)error
d) ........
ans : a
370. if x is even, then
(x%2)=0
x &1 !=1
x! ( some stuff is there)
371. Which of the following about the following two declaration is true
i ) int *F()
ii) int (*F)()
Choice :
a) Both are identical
b) The first is a correct declaration and the second is wrong
c) The first declaraion is a function returning a pointer to an integer and the
second is a pointer to function returning int
d) Both are different ways of declarin pointer to a function
main()
{
int x=7;
int y=3;
dprintf(x/y);
}
Choice:
a) #2 = 2 b) expr=2 c) x/y=2 d) none
Answer: c)x/y=2
main()
{
char *c;
int *p;
c =(char *)malloc(100);
ip=(int *)c;
free(ip);
}
ans: The code functions properly releasing all the memory allocated
374.output of the following.
main()
{
int i;
char *p;
i=0X89;
p=(char *)i;
p++;
printf("%x\n",p);
}
ans:0X8A
375.
which of the following is not a ANSI C language keyword?
ans:Function.
376. When an array is passed as parameter to a function, which of the following statement is correct
choice:
a) The function can change values in the original array
b) In C parameters are passed by value. The funciton cannot change the original value in the array
c) It results in compilation error when the function tries to access the
elements in the array
d) Results in a run time error when the funtion tries to access the elements in
the array
377. The type of the controlling expression of a switch statement cannot be of the
type
Answer : d)float
a) 3 b) 5 c) 6 d) a+18 e) None
Answer : 5
a) 7 b) 28 c) 3 d) 14 e) None
ans: 3;
Answer : b) 3,4
if(a=3)
b++;
printf("%d %d\n",a,b++);
}
Answer : d) 3,7
Answer: d) NULL
main()
{
int l=6;
switch(l)
{ default : l+=2;
case 4: l=4;
case 5: l++;
break;
}
printf("%d",l);
}
a)8 b)6 c)5 d)4 e)none
Answer : c)5
Answer:d)10,22
392.{
int a[]={10,20,30,40,50};
fun(a+1);
}
fun(int *p)
{
for(int i=1;i<=3;i++)
printf("%d",*(p+i));
}
int x=monday;
value of x?
o/p?
#undef ADD;
fun();
}
fun()
{
#if not defined(ADD)
define ADD(X+Y) X*Y
int y=ADD(3,2);
printf("%d",y);
}
o/p?
397) main( )
{ int x,y, z;
x=2;
y=5;
z= x+++y;
printf("%d %d %d", x, y z); }
a)3 5 7 b)option 2 c)option 3 d)option 4
Ans: a
main( )
{ int i, j, temp;
i=5;
j=10;
temp=0;
if( i > j)
swap( i, j );
printf( "%d %d %d", i, j, temp);
}
Ans: On compiling i got ans 10, 0, 0. I did not understand the concept.
399. Which is a good way of representing varaibles in recursion
a) local variables
b) static varaibles
c) global variables
func()
{
static int i = 10;
printf("%d",i);
i++;
}
main()
{ int i = 5, j = 2;
func(&i,&j);
printf("%d %d", i, j);}
main()
{char *a="new";
x(a);
printf("%s",a);
}
The output is
a) Hello
b) New
c) Hello new
d) Run time error
.
403
f(char *p)
{
p[0]? f(++p):1;
printf("%c",*p);
}
if call that fuction with f(Aabcd) what is the output??
ans:dcbaA (Just reversing the string
404
f(char *p)
{
p=(char *)malloc(sizeof(6));
strcpy(p,"HELLO");
}
main()
{
char *p="BYE";
f(p)
printf("%s",p);
}
what is the o/p???
ans:HELLO
405
To sorting array of 10 elements which sorting is best
a)slection
b)bubble
c)tree sort
d)....
ans:a
main() main()
{ {
int fact; int fact=0
long int x; for(i=1;i<=n;i++)
fact=factoral(x); fact=fact*i;
} }
if(x>1) return(x*factorial(x-1);
}
a) program 1;
b) program 2;
c) both 1 &2
d) none
409)
main(){
char str[5]="hello";
if(str==NULL) printf("string null");
else printf("string not null");
}
what is out put of the program?
a) string is null b) string is not null c) error in program d) it executes but p
rint nothing
410)
411)
void f(int *p){
static val=100;
val=&p;
}
main(){
int a=10;
printf("%d ",a);
f(&a);
printf("%d ",a);
}
what will be out put?
a)10,10
412)
struck a{
int x;
float y;
char c[10];
}
union b{
int x;
float y;
char c[10];
}
which is true?
a) size of(a)!=sizeof(b);
b)
c)
d)
413)
# define f(a,b) a+b
#defiune g(c,d) c*d
414)
415)
main()
{
char a[10]="hello";
strcpy(a,'\0');
printf("%s",a);
}
out put of the program?
a) string is null b) string is not null c) program error d)
416)
int f(int a)
{
a=+b;
//some stuff
}
main()
{
x=fn(a);
y=&fn;
what are x & y types
a) x is int y is pointer to afunction which takes integer value
a) b) c) d)
418.main()
{
int i,*j;
i=5;
j=&i;
printf("\ni= %d",i);
f(j);
printf("\n i= %d",i);
}
void f(int*j)
{
int k=10;
j= &k;
}
output is
a 5 10
b 10 5
c55
d none
419
main()
{
int *s = "\0";
if(strcmp(s,NULL)== 0)
printf("\n s is null")p
else
printf("\n s is not null");
}
420). Find the outpur of the following C program
void f(char *p)
{p=(char *) malloc(6);
strcpy(p,”hello”);
}
void main( )
{char *P=”bye”;
f(p);
printf(“%s’,p);
}
423. The following function gives some error. What changes have to be made
void ( int a,int b)
{
int t; t=a; a=b; b=t;
}
a) define void as int and write return t
b) change everywhere a to *a and b to *b
Q425. include<stdio.h>
void swap(int*,int*);
main()
{
int arr[8]={36,8,97,0,161,164,3,9}
for (int i=0; i<7; i++)
{
for (int j=i+1; j<8;j++)
if(arr[i]<arr[j]) swap(&arr[i],&arr[j]);
}
}
void swap(int*x,int*y)
{
int temp; static int cnt=0;
temp= *x;
*x=*y;
*y=temp;
cnt++;
}
What is cnt equal to
a) 7
b) 15
c) 1
d) none of these
If text.dat file is already present after compiling and execution how many bytes does the file occupy ?
a) 0 bytes
b) 5 bytes
c) 11 bytes
d) data is insufficient
Q427. f1(int*x,intflag)
int *y;
*y=*x+3;
switch(flag)
{
case 0:
*x=*y+1;
break;
case 1:
*x=*y;
break;
case 2:
*x=*y-1;
break;
}
return(*y)
main()
{
*x=5;
i=f1(x,0); j=f1(x,1);
printf(“%d %d %d “,i,j,*x);
}
a) 8 8 8
b) 5 8 8
c) 8 5 8
d) none of these
429. foo()
int foo(int a, int b){
if (a&b) return 1;
return 0;
}
433. include<stdio.h>
void swap(int*,int*);
main()
{
int arr[8]={36,8,97,0,161,164,3,9}
for (int i=0; i<7; i++)
for (int j=i+1; j<8;j++)
if(arr[i]<arr[j]) swap(&arr[i],&arr[j]);
}
void swap(int*x,int*y)
{
int temp; static int cnt=0;
temp= *x;
*x=*y;
*y=temp;
cnt++;
}
cnt = ?
a) 7 b) 15 c)1 d)
435. f1(int*x,intflag)
int *y;
*y=*x+3;
switch(flag){
case 0:.........
....
........
break;
case 1:
*x=*y;
break;
case 2:
............
.......
.......
break;
}
return(*y)
main()
{
*x=5;
i=f1(x,0); j=f1(x,1);
printf("%.........",i,j,*x);
}
439. In the following code segment what will be the result of the function,
value of x , value of y
{unsigned int x=-1;
int y;
y = ~0;
if(x == y)
printf("same");
else
printf("not same");
}
a) same, MAXINT, -1
b) not same, MAXINT, -MAXINT
c) same , MAXUNIT, -1
d) same, MAXUNIT, MAXUNIT
e) not same, MAXINT, MAXUNIT
Ans. (a)
char **p="Hello";
printf("%s",**p);
449 2.main()
printf("%d%c\n");
printf("%d%c\n");
450. main()
int x=5;
printf("%d%d",x++,++x);
}
Ans=6 6
451. main()
int x=4;
printf("%d",printf(" %d %d ",x,x) );
}
Ans: 4 4 5
452. main()
{
union
{
int i;
char p;
struct
{
int t;
char e;
char o;
}w;
}l;
printf("%d\n",sizeof(l) );
}
Ans: 4
453. main()
{
int i=0,n=6;
while(n-->0);
i+=n;
printf("%d\n",i);
}
Ans: -1
454. main( )
{
char a[]="Hello";
printf("%c\n",*a++);
Ans: Error
455. a=3,b=2,c=1;
456. main()
{
int a=3;
do
{
printf("%d", a);
a=-1;
} while(a>0);
}
Ans: 3
main()
{
char c=-32;
int i=-64;
unsigned u=-26;
if(c>i)
printf("PASS1");
if( i < c)
printf("PASS2");
else
printf("FAIL1");
if(i<u)
printf("PASS2");
else
printf("FAIL2");
}
Ans: PASS1 PASS2 PASS1
458.
main()
{
int i=0;
for( i=0; i<=20;i++)
{
switch(i)
{
case 0: i+=5;
case 1: i+=2;
case 2: i+=5;
default: i+=4;
break;
}
printf("%d",i);
}
Ans: 16 21
459.main()
{
int i=4;
switch(i)
{
case 1:
printf("HEllo"):
case default: // "case" should not come with "default"
printf("****");
}
}
Ans: Error
460
main()
{
int sum=0,count;
for(count=1;sum+=count)
printf("%d\t",sum);
}
Ans: Error
461.
#define cond(a) a>=65 && a<=90
main()
{
char s='R';
if( cond(s) )
printf("UPPER CASE");
else
printf("LOWER CASE");
}
Ans:UPPER CASE
461.main()
{
static int i=5;
printf("%d\t",i--);
if( i)
main();
}
Ans: 5 4 3 2 1
462. main()
{
char *a1="new",*a2="dictionary",*t;
swap(a1,a2);
printf("(%s%s)",a1,a2);
t=a1;
a1=a2;
a2=t;
printf("-(%s%s)",a1,a2);
>}
swap( char *s1,char *s2)
{
char *temp;
s1=s2;
s2=s1;
temp=s1;
}
Ans: (newdictionary)-(dictionarynew)
463.
*p++?
464.
main()
{
}
Ans: 50
471. if (a>b)
if(b>c)
s1;
else s2;
s2 will be executed if
(a) a<= b,
(b) b>c,
(c) b<=c and a<=b,
(d) a>b and b<=c.
472. main()
{
inc(); ,inc(); , inc();
}
inc()
{ static int x;
printf("%d", ++x);
}
prints
(a) 012,
(b) 123,
(c) 3 consecutive unprectiable numbers
(d) 111.
473.preprocessing is done
475.main()
{
int a=5,b=2;
printf("%d", a+++b);
}
(a) results in syntax,
(b) print 7,
(c) print 8,
(d) none,
476. process by which one bit patten in to another by bit wise operation is
(a) masking,
(b) pruning,
(c) biting,
(d) chopping,
479. declaration
enum cities{bethlehem,jericho,nazareth=1,jerusalem}
assian value 1 to
(a) bethlehem
(b) nazareth
(c)bethlehem & nazareth
(d)jericho & nazareth
480. #include<conion.h>
#include<stdio.h>
void main()
{
char buffer[82]={80};
char *result;
printf( "input line of text, followed by carriage return :\n");
result = cgets(buffer);
printf("text=%s\n",result);
}
(a) printf("length=%d",buffer[1]);
(b) printf("length=%d",buffer[0]);
(c) printf("length=%d",buffer[81]);
(d) printf("length=%d",buffer[2]);
487
. i =5;
i= (++i)/(i++);
printf( "%d" , i);
prints ,
(a) 2
(b) 5
(c) 1
(d) 6
CHAR S;
CHAR S[6]= " HELLO";
PRINTF("%S ",S[6]);
(A) 0
(B) ASCII 0
(C) I
(D) UNPREDICTABLE
UNSIGNED CHAR C;
FOR ( C=0;C!=256;C++2)
PRINTF("%D",C);
(A) 127
(B) 128
(C) 256
(D) INFINITELY
Struct(s)
{int a;
long b;
}
Union (u)
{int a;
long b;
}
Switch (i)
i=1;
case 1
i++;
case 2
++i;
break;
case 3
--i;
char S;
char S[6]= " HELLO";
printf("%s ",S[6]);
(a) 0
(b) ASCII 0
(c) I
(d) unpredictable
Unsigned char c;
for(c=0;c!=256;c++2)
printf("%d",c);
int i;
i=2;
i++;
if(i==4)
{printf(i=4);
}
else
{printf(i=3);
}
a) 4
b) 3
c) unpredictable
d) none
Ans. (b)
Ans. (a)
496. Struct(s)
{
int a;
long b;
}
Union (u)
{int a;
long b;
}
Print sizeof(s)and sizeof(u) if sizeof(int)=4 and sizeof(long)=4
497.Switch (i)
i=1;
case 1
i++;
case 2
++i;
break; ( ans : 1,2,3,none)
case 3
--i;
Output of i after executing the program
498. char S;
char S[6]= " HELLO";
printf("%s ",S[6]);
:2
:3
:4
:8
:foo()
:constructor foo() destructor
:constructor destructor
:No output
Q503. In the following class, the compiler will automatically add the following functions to the class
class foo{}
:0x0000
:0xFFFF
:0xffff
:Will crash when run
int i = 50;
void foo(int i)
{
i *= 2;
}
void main()
{
int i=1;
foo(i);
printf("%d", i);
}
:1
:2
:50
:100
Q507. Consider the function declaration and choose the correct statement
:The function foo is a valid declaration, and foo can not change the value of i
:The function foo is a valid declaration, and foo can not change the value of the member variables of the
class to which it belongs
:The function foo is a valid declaration, and foo can not be overriden in the derived class
:The function foo is a valid declaration and foo can not be overloaded
int foo()
{
static int i=0;
i++;
return i;
}
void main()
{
printf("%d ", foo());
printf("%d ", foo());
printf("%d ", foo());
}
:Compilation Error
:0 0 0
:1 1 1
:1 2 3
:Compilation Error
:1 2 4
:2 2 2
:4 4 4
/*
Assume sizeof char=1, int=2, float=4
Assume sizeof a pointer =4
*/
class base
{
private:
int i;
}
class derived : private base
{
public:
int i;
}
void main()
{
base b;
derived d;
cout << sizeof(base) << " " << sizeof(b) << " " << sizeof(derived) << " " << sizeof(d);
}
:2 2 2 2
:2 2 4 4
:2 4 4 4
:2 4 2 4
e1.sal = 50.0;
e1.name = (char *) malloc(30);
strcpy(e1.name, "Sachin 10 the great.");
:8 8
:8 30
:8 34
:8 38
In what order are the operators executed, state them from the first executed to the last executed.
:-- * ++
:* -- ++
:++ -- *
:* ++ --
e1.sal = 50.0;
e2.sal = 150.0;
e1.name = (char *) malloc(20);
e2.name = (char *) malloc(20);
e1 = e2;
:5
:10
:11
:25
:Compilation Error
:1 2 4
:2 2 2
:4 4 4
:Base
:Dervied
:Dervied1
:A Compilation error
void foo(void)
{ i++; }
void show()
{ cout << i << " "; }
};
static int foobar::i;
void main()
{
foobar f1,f2,f3 ;
f1.foo();
f2.foo();
f2.foo();
f1.show();
f3.show()
getch();
}
:0 0
:2 1
:2 0
:6 6
Q523. What happens when you increment a void* ?
:Compilation error.
:It goes up by the size of a pointer.
:It goes up by the size of the type it is pointing to.
:Run Time error
Q524. What happens when you increment a void** ?
:Compilation error
:It goes up by the size of a pointer
:It goes up by the size of the type it is pointing to
:Run Time error
Q526. What will be the output of the following program
void main()
{
int i;
printf("%d", i);
}
:0
:-1
:0xFFFF
:Garbage
Q529. For a class Circle, the protortype of the copy constructor is:
:Circle()
:Circle(Circle&)
:Circle(Circle*)
:Circle Circle()
Q530. Consider the following code snippet and choose the correct statement
class Base
{
int Show( ) { printf( "Base" ); } ;
}
}
:Base
:Dervied
:Dervied1
:A Compilation error
class foo
{
public:
char *c;
float f;
}
void main()
{
foo f;
cout << sizeof(foo) << " " << sizeof(f);
}
:free(nPtr);
:free( nPtr->firstname ); free( nPtr->lastname ); nPtr=NULL;
:free( nPtr->firstname ); free( nPtr->lastname ); free(nPtr);
:free(nPtr); free( nPtr->firstname ); free( nPtr->lastname );
Q533. You have to write a program where that implements a doubly linklist. Each node will store a float.
The node declaration will have how many entries?
:2
:3
:4
:5
Q534. You have to write a program where that implements a cirlular linklist. Each node will store a char*.
The node declaration will have how many entries?
:2
:3
:4
:5
Q535. What is the output of the following program:
class base
{
public:
base()
{ cout << "In base()";}
base(int i)
{ cout << "In base(int)";}
}
class derived : private base
{
public:
derived()
{ cout << "In derived()";}
derived(int i)
{ cout << "In derived(int)";}
}
void main()
{
dreived d(100);
}
Q537. What should be the prototype of a function that swaps two float pointers?
/*
Assume sizeof char=1, int=2, float=4
Assume sizeof a pointer =4
*/
void main()
{
char *cp = (char *) 0x0000;
int *ip = (int *) 0x0000;
float *fp = (float *) 0x0000;
:1 1 1
:1 2 4
:2 2 2
:4 4 4
Q539. What is the output of the followng program:
void main()
{
char *p = (char*) malloc( strlen("Keep the faith") );
strcpy(p,"Keep the faith" );
printf("%s", p);
}
:Compilation error
:Keep the faith
:Keep the faith
:Garbage
:Base
:Dervied
:Dervied1
:A Compilation error
Q541. How do you catch all exceptions in C++?
:catch( all )
:catch(Exception)
:catch( void* )
:catch(...)
Q542. Which statement is not true:
class base
{
public:
void foo()
{ cout << "base::foo()"; }
};
void main()
{
derived d = new d();
d->foo();
}
:base::foo()
:deived::foo()
:Error: Cannot access private member foo in main()
:Error: Ambigous call to foo()
Q544. In C you can,
int foo()
{
static int i=0;
i++;
return i;
}
void main()
{
printf("%d ", foo());
printf("%d ", foo());
printf("%d ", foo());
}
:Compilation Error
:0 0 0
:1 1 1
:1 2 3
Q546. What is the output of the followng program:
void main()
{
char *p = 0x0000;
foo(p);
printf("%X", p);
}
:0x0000
:0xFFFF
:0xffff
:Will crash when run
Q547. When a class is derived from the base class with protected access specifier
eg class A : protected B
:Only the protected members of class B are accessible in class A
:Only the protected and public members of class B are accessible in class A
:Only the public members of class B are accessible in class A
:None of the members of class B are accessible in class A
Q548. What will be the output of the following program
/*
Assume sizeof char=1, int=2, float=4
Assume sizeof a pointer =4
*/
void main()
{
char *cp;
int *ip;
float *fp;
:Compilation Error
:1 2 4
:2 2 2
:4 4 4
Question :
class base
{
public:
base()
{ cout << "In base()";}
base(int i)
{ cout << "In base(int)";}
void main()
{
dreived d(100);
}
--*p++;
In what order are the operators executed, state them from the first executed to the last executed.
:-- * ++
:* -- ++
:++ -- *
:* ++ --
Q551. You have to write a program where that implements a cirlular linklist. Each node will store a char*.
The node declaration will have how many entries?
:2
:3
:4
:5
Q552. A vtable contains :
void main()
{
int i;
printf("%d", i);
}
:0
:-1
:0xFFFF
:Garbage
Q554. What is the output of the following program:
struct employee
{
char* name;
float sal;
};
void main()
{
struct employee e1, e2;
e1.sal = 50.0;
e2.sal = 150.0;
e1.name = (char *) malloc(20);
e2.name = (char *) malloc(20);
e1 = e2;
class foo{}
:The default constructor & destructor
:The overloaded = operator
:The copy constructor
:All of the above
Q556. What will be the output of the following program
/*
Assume sizeof char=1, int=2, float=4
Assume sizeof a pointer =4
*/
class employee
{
char *name;
public:
employee() {}
virtual ~employee() {}
}
void main()
{
employee e;
:0
:4
:8
:Garbage
Q557. What will be the output of the following program:
/*
Assume sizeof char=1, int=2, float=4
Assume sizeof a pointer =4
*/
union endian
{
unsigned int i;
char c;
};
void main()
{
printf("%d", sizeof(union endian) );
}
:2
:3
:4
:8
Q558. What happens when you increment a void* ?
:Compilation error.
:It goes up by the size of a pointer.
:It goes up by the size of the type it is pointing to.
:Run Time error
Q559. What will be the output of the following program
int i = 50;
void foo(int i)
{
i *= 2;
}
void main()
{
int i=1;
foo(i);
printf("%d", i);
}
:1
:2
:50
:100
Q560. We cannot have a private destructor because :
:The compiler cannot access the destructor when destroying the class
:The operating system cannot access the destructor when destroying the class
:We can have a private destructor provided it is a virtual destructor
:We canot have private destructor
Q561. What should be the prototype of a function that swaps two float pointers?
void main(void)
{
int i=0;
int &iref=i;
int j=10;
iref=j;
:0 12 12
:12 12 11
:13 13 13
:2 2 11
Q563. Consider the following code snippet:
class foo()
{
foo() {}
}
void main()
{
foo fArr[100];
}
In what sequence are the destructors called:
void main()
{
char *p = (char*) malloc( strlen("Keep the faith") );
strcpy(p,"Keep the faith" );
printf("%s", p);
}
:Compilation error
:Keep the faith
:Keep the faith <followed by garbage>
:Garbage
Q565. You have to write a program where that implements a doubly linklist. Each node will store a float.
The node declaration will have how many entries?
:2
:3
:4
:5
Q566. What will be the output of the following program:
class mox
{
public:
mox()
{
cout << "constructor " ;
}
void foo()
{
cout << "foo() " ;
}
~mox()
{
cout << "destructor " ;
}
};
void main()
{
mox *m;
m=(mox *) malloc(sizeof(mox));
m->foo();
free(m);
}
:foo()
:constructor foo() destructor
:constructor destructor
:No output
Q567. What is the output of the following program:
class foo
{
int i;
public:
foo() : i(10)
{}
void show()
{
cout << i;
}
}
void main()
{
foo f;
f.show();
}
:Compilation error
:Gabage
:0
:10
Q557. What is the output of the following program:
/*
Assume sizeof char=1, int=2, float=4
Assume sizeof a pointer =4
*/
class foo
{
public:
char *c;
float f;
}
void main()
{
foo f;
cout << sizeof(foo) << " " << sizeof(f);
}
:The function foo is a valid declaration, and foo can not change the value of i
:The function foo is a valid declaration, and foo can not change the value of the member variables of the
class to which it belongs
:The function foo is a valid declaration, and foo can not be overriden in the derived class
:The function foo is a valid declaration and foo can not be overloaded
main()
{
Derived2 obj2;
Base *pBase = NULL;
pBase = &obj2;
pBase->Show();
:Base
:Dervied
:Dervied1
:A Compilation error
Q561. What happens when you increment a void** ?
:Compilation error
:It goes up by the size of a pointer
:It goes up by the size of the type it is pointing to
:Run Time error
Q562. delete NULL;
/*
Assume sizeof char=1, int=2, float=4
Assume sizeof a pointer =4
*/
void main()
{
char *cp = (char *) 0x0000;
int *ip = (int *) 0x0000;
float *fp = (float *) 0x0000;
:1 1 1
:1 2 4
:2 2 2
:4 4 4
Q564. Consider the following code:
struct node
{
char *firstname;
char *lastname;
char node* next;
};
void main()
{
struct node *nPtr = (struct node *) malloc( sizeof(struct node) );
nPtr->firstname = (char*) malloc(10);
nPtr->lastname = (char*) malloc(10);
nPtr->next = NULL;
What is the correct way the deallocate memory in the above program.
:free(nPtr);
:free( nPtr->firstname ); free( nPtr->lastname ); nPtr=NULL;
:free( nPtr->firstname ); free( nPtr->lastname ); free(nPtr);
:free(nPtr); free( nPtr->firstname ); free( nPtr->lastname );
Q565. What is the output of the following program:
/*
Assume sizeof char=1, int=2, float=4
Assume sizeof a pointer =4
*/
class base
{
private:
int i;
}
void main()
{
base b;
derived d;
cout << sizeof(base) << " " << sizeof(b) << " " << sizeof(derived) << " " << sizeof(d);
}
:2 2 2 2
:2 2 4 4
:2 4 4 4
:2 4 2 4
Q37. What will be the output of the following program
#define SQUARE(x) x * x
void main()
{
printf("%d ", SQUARE(3+2));
}
:5
:10
:11
:25
Q566. What will be the output of the following:
class Base
{
public :
virutal int Show( ) { printf( "Base" ); } ;
}
main()
{
Derived2 obj2;
Base *pBase = NULL;
pBase = &obj2;
pBase->Show();
:Base
:Dervied
:Dervied1
:A Compilation error
Q567. For a class Circle, the protortype of the copy constructor is:
:Circle()
:Circle(Circle&)
:Circle(Circle*)
:Circle Circle()
Q568. Difference between Encapsulation and Data abstraction is that :
569. A long C program is given -- try to be familiar with few of the concepts listed below
int *num={10,1,5,22,90};
main()
{
int *p,*q;
int i;
p=num;
q=num+2;
i=*p++;
print the value of i, and q-p, and some other operations are there.
}
how the values will change?
a) Error at runtime
b) Compilation error
c) 2 3
d) 3 2
a) aabbcc
b) aabbcc123
c) abcabc123
d) infinate loop
a) -1
b) 1
c) 65336
int x=2;
x=x<<2;
printf("%d ",x);
Ans. 8
a) 2
b) 1
c) 5
d) 3
580. How can the word YES be stored in any array.
a)
array[1] = 'Y'
array[2] = 'E'
array[3] = 'S'
array[4] = '\0'
b)
array[0] = "Y"
array[1] = "E"
array[2] = "S"
array[3] = "\0"
c)
array[1] = "Y"
array[2] = "E"
array[3] = "S"
d)
array[0] = 'Y'
array[1] = 'E'
array[2] = 'S'
array[3] = '\0'
581. What is true about the following C functions?
(A) Need not return any value. (B) Should always return an integer.
(C) Should always return a float. (D) Should always return more than one value.
582. enum number { a=-1, b=4, c,d,e,} what is the value of e?
(A) 7 (B) 4 (C) 5 (D) 3
23. Which of the following about automatic variables within a function is correct?
(A) Its type must be declared before using the variable. (B) They are local.
(C) They are not initialized to zero. (D) They are global.
**(a+3+4)
*(a+3)+*(a+4)
**(a+3)+4
*(*(a+2)+4)
case 0:
i+=5;
case 1:
i+=2;
case 5:
i+=5;
default:
i+=4;
break;
}
}
}
(A) 5,9,13,17 (B)12,17,22 (C) 16,21
(D) syntax error.
596 What will be the result of the following program?
char*g()
{
static char x[1024];
return x;
}
main()
{
char*g1="First String";
strcpy(g(),g1);
g1=g();
strcpy(g1,"Second String");
printf("Answer is:%s", g());
}
(A) Answer is: First String
(B) Answer is: Second String
(C) Run time Error/Core Dump
(D) None of these
void zap(int n)
{
if(n<=1)
zap =1;
else
zap= zap(n-3)+zap(n-5);
void main()
{
zap(6);
}
598)
void main()
{
char i,j;
i=255,j=255;
cout<<i<<j;
}
599)
#define STYLE char
void main()
{
600)
class base
{
int top;
base()
{
top=1;
}
top=2;
cout<<top;
cout<<base()::top;
cout<<::top;
}
void main()
{
derived d;
}
601)
void main()
{
int n;
-------------
Some Complex statements on n;
--------------
cout<<precision(n);
}
602)
void main()
{
int i;
if ( odd(i) )
{
cout<<i;
}
}
604)
605)
606)
# ifdef TRUE
int I=0;
#endif
void main()
{
int j,k;
j=5;k=4;
cout<<I<<j<<k;
}
607)
void val()
{
------------------
Some Statements;
-------------
}
void main()
{
enum grade{GRAD,BAD,GOOD};
BAD.val();
}
608.
main()
{
char *p1="Name";
char *p2;
p2=(char *)malloc(20);
while(*p2++=*p1++);
printf("%s\n",p2);
}
609.
main()
{
int x=20,y=35;
x = y++ + x++;
y = ++y + ++x;
printf("%d %d\n",x,y);
}
Ans 57 94
610.
main()
{
int x=5;
printf("%d %d %d\n",x,x<<2,x>>2);
}
Ans 5 20 1
611
#define swap1(a,b) a=a+b;b=a-b;a=a-b;
main()
{
int x=5,y=10;
swap1(x,y);
printf("%d %d\n",x,y);
swap2(x,y);
printf("%d %d\n",x,y);
}
Ans 10 5
10 5
611).
main()
{
char *ptr = "Ramco Systems";
(*ptr)++;
printf("%s\n",ptr);
ptr++;
printf("%s\n",ptr);
}
Ans Samco Systems
amco Systems
612).
#include<stdio.h>
main()
{
char s1[]="Ramco";
char s2[]="Systems";
s1=s2;
printf("%s",s1);
}
613).
#include<stdio.h>
main()
{
char *p1;
char *p2;
p1=(char *) malloc(25);
p2=(char *) malloc(25);
strcpy(p1,"Ramco");
strcpy(p2,"Systems");
strcat(p1,p2);
printf("%s",p1);
}
Ans : RamcoSystems
# define TRUE 0
some code
while(TRUE)
{
some code
Modify_value()
{
return (x+=10);
}
change_value()
{
return(x+=1);
}
Ans : 12 1 1
116).
main()
{
int x=10,y=15;
x=x++;
y=++y;
printf("%d %d\n",x,y);
}
Ans : 11 16
618).
main()
{
int a=0;
if(a=0) printf("Ramco Systems\n");
printf("Ramco Systems\n");
}
Ans : Ony one time
"Ramco Systems"
will be printed
I
619 #INCLUDE<STDIO.H>
INT SUMELEMENT(INT *,INT);
VOID MAIN(VOID)
{
INT X[10];
INT I=10;
FOR(;I;)
{
I--;
*(X+I)=I;
}
PRINTF("%D",SUMELEMENT(X,10));
}
INT SUMELEMENT(INT ARRAY[],INT SIZE)
{
INT I=0;
FLOAT SUM=0;
FOR(;I<SIZE;I++)
SUM+=ARRAY[I];
RETURN SUM;
}
#INCLUDE<STDIO.H>
VOID MAIN(VOID);
INT PRINTF(CONST CHAR*,...);
VOID MAIN(VOID)
{
INT I=100,J=10,K=20;
-- INT SUM;
FLOAT AVE;
CHAR MYFORMAT[]="AVE=%.2F";
SUM=I+J+K;
AVE=SUM/3.0;
PRINTF(MYFORMAT,AVE);
}
#INCLUDE<STDIO.H>
VOID MAIN(VOID);
{
INT A[10];
PRINTF("%D",((A+9) + (A+1)));
}
#INCLUDE<STDIO.H>
VOID MAIN(VOID)
{
STRUCT S{
INT X;
FLOAT Y;
}S1={25,45.00};
UNION U{
INT X;
FLOAT Y;
} U1;
U1=(UNION U)S1;
PRINTF("%D AND %F",U1.X,U1.Y);
}
#INCLUDE<STDIO.H>
VOID MAIN(VOID)
{
UNSIGNED INT C;
UNSIGNED X=0X3;
SCANF("%U",&C);
SWITCH(C&X)
{
CASE 3: PRINTF("HELLO!\T");
CASE 2: PRINTF("WELCOME\T");
CASE 1: PRINTF("TO ALL\T");
DEFAULT:PRINTF("\N");
}
}
#INCLUDE<STDIO.H>
INT FN(VOID);
VOID PRINT(INT,INT(*)());
INT I=10;
VOID MAIN(VOID)
{
INT I=20;
PRINT(I,FN);
}
VOID PRINT(INT I,INT (*FN1)())
{
PRINTF("%D\N",(*FN1)());
}
INT FN(VOID)
{
RETURN(I-=5);
}
#INCLUDE<STDIO.H>
VOID MAIN(VOID);
{
CHAR NUMBERS[5][6]={"ZERO","ONE","TWO","THREE","FOUR"};
PRINTF("%S IS %C",&NUMBERS[4][0],NUMBERS[0][0]);
}
INT BAGS[5]={20,5,20,3,20};
VOID MAIN(VOID)
{
INT POS=5,*NEXT();
*NEXT()=POS;
PRINTF("%D %D %D",POS,*NEXT(),BAGS[0]);
}
INT *NEXT()
{
INT I;
FOR(I=0;I<5;I++)
IF (BAGS[I]==20)
RETURN(BAGS+I);
PRINTF("ERROR!");
EXIT(0);
}
#INCLUDE<STDIO.H>
VOID MAIN(VOID)
{
INT Y,Z;
INT X=Y=Z=10;
INT F=X;
FLOAT ANS=0.0;
F *=X*Y;
ANS=X/3.0+Y/3;
PRINTF("%D %.2F",F,ANS);
}
#INCLUDE<STDIO.H>
VOID MAIN(VOID);
{
DOUBLE DBL=20.4530,D=4.5710,DBLVAR3;
DOUBLE DBLN(VOID);
DBLVAR3=DBLN();
PRINTF("%.2F\T%.2F\T%.2F\N",DBL,D,DBLVAR3);
}
DOUBLE DBLN(VOID)
{
DOUBLE DBLVAR3;
DBL=DBLVAR3=4.5;
RETURN(DBL+D+DBLVAR3);
}
#INCLUDE<STDIO.H>
STATIC INT I=5;
VOID MAIN(VOID)
{
INT SUM=0;
DO
{
SUM+=(1/I);
}WHILE(0<I--);
}
#INCLUDE<STDIO.H>
VOID MAIN(VOID)
{
INT OLDVAR=25,NEWVAR=-25;
INT SWAP(INT,INT);
SWAP(OLDVAR,NEWVAR);
PRINTF("NUMBERS ARE %D\T%D",NEWVAR,OLDVAR);
}
INT SWAP(INT OLDVAL,INT NEWVAL)
{
INT TEMPVAL=OLDVAL;
OLDVAL=NEWVAL;
NEWVAL=TEMPVAL;
}
#INCLUDE<STDIO.H>
VOID MAIN(VOID);
{
INT I=100,J=20;
I++=J;
I*=J;
PRINTF("%D\T%D\N",I,J);
}
#INCLUDE<STDIO.H>
VOID MAIN(VOID);
INT NEWVAL(INT);
VOID MAIN(VOID)
{
INT IA[]={12,24,45,0};
INT I;
INT SUM=0;
FOR(I=0;IA[I];I++)
{
SUM+=NEWVAL(IA[I]);
}
PRINTF("SUM= %D",SUM);
}
INT NEWVAL(INT X)
{
STATIC INT DIV=1;
RETURN(X/DIV++);
}
#INCLUDE<STDIO.H>
VOID MAIN(VOID);
{
INT VAR1,VAR2,VAR3,MINMAX;
VAR1=5;
VAR2=5;
VAR3=6;
MINMAX=(VAR1>VAR2)?(VAR1>VAR3)?VAR1:VAR3:(VAR2>VAR3)?VAR2:VAR3;
PRINTF("%D\N",MINMAX);
#INCLUDE<STDIO.H>
VOID MAIN(VOID);
{
VOID PA(INT *A,INT N);
INT ARR[5]={5,4,3,2,1};
PA(ARR,5);
}
VOID PA(INT *A,INT N)
{
INT I;
FOR(I=0;I<N;I++)
PRINTF("%D\N",*(A++)+I);
}
#INCLUDE<STDIO.H>
VOID MAIN(VOID);
VOID PRINT(VOID);
{
PRINT();
}
VOID F1(VOID)
{
PRINTF("\NF1():");
}
#INCLUDE "6.C"
VOID PRINT(VOID)
{
EXTERN VOID F1(VOID);
F1();
}
STATIC VOID F1(VOID)
{
PRINTF("\N STATIC F1().");
}
#INCLUDE<STDIO.H>
VOID MAIN(VOID);
STATIC INT I=50;
INT PRINT(INT I);
VOID MAIN(VOID)
{
STATIC INT I=100;
WHILE(PRINT(I))
{
PRINTF("%D\N",I);
I--;
}
}
INT PRINT(INT X)
{
STATIC INT I=2;
RETURN(I--);
}
#INCLUDE<STDIO.H>
VOID MAIN(VOID);
TYPEDEF STRUCT NTYPE
{
INT I;
CHAR C;
LONG X;
} NEWTYPE;
VOID MAIN(VOID)
{
NEWTYPE *C;
C=(NEWTYPE *)MALLOC(SIZEOF(NEWTYPE));
C->I=100;
C->C='C';
(*C).X=100L;
PRINTF("(%D,%C,%4LD)",C->I,C->C,C->X);
}
#INCLUDE<STDIO.H>
VOID MAIN(VOID);
CONST INT K=100;
VOID MAIN(VOID)
{
INT A[100];
INT SUM=0;
FOR(K=0;K<100;K++)
*(A+K)=K;
SUM+=A[--K];
PRINTF("%D",SUM);
}
642) which of the following code will swap the two numbers? -3 choices was given
646 ) if the string " this is a " is present in the code of a function such as 'void func(void)' where will the
variable stored in the memory.
a) in the stack b) heap c) code or text segment as per implementation d) created when func is called,
stored in function stack space and destroyed as it goes out .
647. If FILE1 and FILE2 are defined what files will be included in the
Program.
#ifdef FILE1
#include file1.h
#elseifdef FILE2
#include file2.1
#elseifdef FILE3
#include file3.h
#endif
648
int a[]={1,2,3,4};
main()
{ printf("%d",sizeof(a));
}
What will be the output of the program when executed.
Ans : 8. if integer takes 2 byte.
649
char name="Krishna Prasad";
main()
{ name[7] = '\0';
printf("%s",name);
}
what's the o/p.
Ans : Compilation error. Since you can't assign a String Constant to
Char variable.
658) C allows
a) only call by value
b) only call by reference
c) both
d) only call by value and sometimes call by reference
671) output?
main ()
{
int i = 2, j = 3, k = 1;
swap (i, j)
printf ("%d %d", i, j);
}
swap (int i, int j)
{
int temp;
temp = i; i = j; j = temp;
}
YOU KNOW THE ANSWER
672) main ()
{
int i = 2;
twice (2);
printf ("%d", i);
}
twice (int i)
{
bullshit
}
678) union {
int no;
char ch;
} u;
What is the output?
u.ch = '2';
u.no = 0;
printf ("%d", u.ch);
a) 2 b) 0 c) null character d) none
a) all
b)
c) iii is valid sometimes
684) main ()
{
char *name = "name";
change (name);
printf ("%s", name);
}
change (char *name)
{
char *nm = "newname";
name = nm;
}
what is the output?
a) name b) newname c) name = nm not valid
d) function call invalid
686) int a = 0, b = 2;
if (a = 0)
b = 0;
else
b *= 10;
what is the value of b?
a) 0 b) 20 c) 2 d) none
687) int x = 2, y = 2, z = 1;
what is the value of x afterh the following statmements?
if (x = y%2)
z = crap
else
crap
a) 0 b) 2 c)1 d)none
688) output?
initially n = -24;
printd (int n)
{
if (n < 0)
{
printf ("-");
n = -n;
}
if (n % 10)
printf ("%d", n);
else
printf ("%d", n/10);
printf ("%d", n);
}
a. -24 b.24 c. d.-224
689) float x, y, z;
scanf ("%f %f", &x, &y);
if input stream contains "4.2 3 2.3 ..." what will x and y contain
after scanf?
a. 4.2, 3.0
b. 4.2, 2.3
c.
d.
int i = 2, j = 3, k = 1;
printf ("%d %d", max(i,j), squre(k));
output?
a.32 b.23 c.31 d.13
i) adr->name X
ii) adradr->name
iii) adr.zip X
iv) adradr.zip
694) main ()
{
}
int a;
f1(){}
f2(){}
695
main ()
{
mixup (a, b, &c);
}
mixup (int p1, char *p2, char **p3)
{
int *temp;
....doesnt matter.....
}
698) main ()
{
char s[] = "T.C.S", *A;
print(s);
}
print (char *p)
{
while (*p != '\0')
{
if (*p != ".")
printf ("%s", *p);
p++;
}
}
output?
a.T.C.S
b.TCS
c.
d. none of the above
699) main ()
{
int ones, twos, threes, others;
int c;
main()
{
int i;
printf("\n %d",i);
f(&i);
printf("\n %d",i);
}
1.10,5
2,10,10
c.5,5
d. none
701. main()
{
int i;
fork();
fork();
fork();
printf("----");
}
702
void f(int i)
{
int j;
for (j=0;j<16;j++)
{
if (i & (0x8000>>j))
printf("1");
else
printf("0");
}
}
what's the purpose of the program
main()
{
int m;
m=2*f(3,g(4,5));
printf("\n m is %d",m);
}
704.
main()
{
char a[10];
strcpy(a,"\0");
if (a==NULL)
printf("\a is null");
else
printf("\n a is not null");}
708.
two program is given of factorial. one with recursion and one without recursion . question was which
program won't run for very big no. input becauseof stack overfow .
a. i only (ans.)
b. ii only
c. i& ii both .
c. none
709
struct a
{
int a;
char b;
int c;
}
union b
{
char a;
int b;
int c;
};
which is correct .
a. size of a is always diff. form size of b.(ans.)
b. size of a is always same form size of b.
c. we can't say anything because of not-homogeneous (not in ordered)
d. size of a can be same if ...
]. The following variable is available in file1.c
710
main()
{
int x=10,y=15;
x=x++;
y=++y;
printf("%d %d\n",x,y);
}
----------------------------------------------------------------------
711
int x;
main()
{
int x=0;
{
int x=10;
x++;
change_value(x);
x++;
Modify_value();
printf("First output: %d\n",x);
}
x++;
change_value(x);
printf("Second Output : %d\n",x);
Modify_value();
printf("Third Output : %d\n",x);
}
Modify_value()
{
return (x+=10);
}
change_value()
{
return(x+=1);
}
----------------------------------------------------------------------------
712
main()
{
int x=20,y=35;
x = y++ + x++;
y = ++y + ++x;
printf("%d %d\n",x,y);
}
-----------------------------------------------------------------------
713
main()
{
char *p1="Name";
char *p2;
p2=(char *)malloc(20);
while(*p2++=*p1++);
printf("%s\n",p2);
}
----------------------------------------------------------------------
714
main()
{
int x=5;
printf("%d %d %d\n",x,x<<2,x>>2);
}
--------------------------------------------------------------------
715
717
main()
{
char *ptr = "Ramco Systems";
(*ptr)++;
printf("%s\n",ptr);
ptr++;
printf("%s\n",ptr);
}
---------------------------------------------------------------------
718
#include<stdio.h>
main()
{
char s1[]="Ramco";
char s2[]="Systems";
s1=s2;
printf("%s",s1);
}
-----------------------------------------------------------------
720
#include<stdio.h>
main()
{
char *p1;
char *p2;
p1=(char *) malloc(25);
p2=(char *) malloc(25);
strcpy(p1,"Ramco");
strcpy(p2,"Systems");
strcat(p1,p2);
printf("%s",p1);
}
Ans. Wrong
Ans. 4
Ans. 10 5 0
Q729. #include<stdarg.h>
show(int t,va_list ptr1)
{
int a,x,i;
a=va_arg(ptr1,int)
printf("\n %d",a)
}
display(char)
{
int x;
listptr;
va_star(otr,s);
n=va_arg(ptr,int);
show(x,ptr);
}
main()
{
display("hello",4,12,13,14,44);
}
Q730. main()
{
printf("hello");
fork();
}
Q731. main()
{
int i = 10;
printf(" %d %d %d \n", ++i, i++, ++i);
}
Q732. #include<stdio.h>
main()
{
int *p, *c, i;
i = 5;
p = (int*) (malloc(sizeof(i)));
printf("\n%d",*p);
*p = 10;
printf("\n%d %d",i,*p);
c = (int*) calloc(2);
printf("\n%d\n",*c);
}
Q735. main()
{
int a=10,b=20;
a>=5?b=100:b=200;
printf("%d\n",b);
}
Q737. #include<stdio.h>
main()
{
char s[] = "Bouquets and Brickbats";
printf("\n%c, ",*(&s[2]));
printf("%s, ",s+5);
printf("\n%s",s);
printf("\n%c",*(s+2));
}
Q738. main()
{
struct s1
{
char *str;
struct s1 *ptr;
};
static struct s1 arr[] = { {"Hyderabad",arr+1},
{"Bangalore",arr+2},
{"Delhi",arr}
};
struct s1 *p[3];
int i;
for(i=0;i<=2;i++)
p[i] = arr[i].ptr;
printf("%s\n",(*p)->str);
printf("%s\n",(++*p)->str);
printf("%s\n",((*p)++)->str);
}