1000 C Programming Questions
1000 C Programming Questions
2.
typedef struct{
char *;
nodeptr next;
} * nodeptr;
what does nodeptr stand
for?
ans:
printf("%c",*f()='A');}
o/p=?
for strcpy function
string.h header file should be
included
semicolon is missing in
strcpy function
leftside function call can
come when it is
returning some pointer
so
*p=A;
3.
struct list{
int x;
struct list *next;
}*head;
the struct head.x =100
Ans: above is correct /
wrong
expl: 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.
7.
8.
main()
{
int a=10,b=5, c=3,d=3;
if (a<b)&&(c=d++)
printf(%d %d %d %d,
a,b,c,d);
4.
else
printf("%d %d %d %d,
main()
{
int i;
i=1;
i=i+2*i++;
printf(%d,i);}
ans: 4
5.
main()
{
FILE *fp1,*fp2;
fp1=fopen("one","w")
fp2=fopen("one","w")
fputc('A',fp1)
fputc('B',fp2)
fclose(fp1)
fclose(fp2)}
a.error b. c. d.
ans: no error. But It will
over writes on same file.
6.
#include<malloc.h>
char *f()
{char *s=malloc(8);
strcpy(s,"goodbye");}
main()
{
char *f();
a,b,c,d);
}
ans: 10 5 3 3 Note: if condition
should be in braces
9.
main()
{
int i = 10;
printf(" %d %d %d \n", ++i,
i++, ++i);
}
ans: 13 11 11
10.
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);
}
y>>=3;PRINT(y);
}
ans: int = 0 int = 3 int =
0
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,2);
printf("\n%d\n",*c);
}
ans: garbage, 5, 10, 0 (malloc gives
garbage and calloc initializes with
zeros)
15.
11.
16.
{
char s[] = "Bouquets and
Brickbats";
printf("\n%c, ",*(&s[2]));
printf("\n%s, ",s+5);
printf("\n%s,",s);
printf("\n%c",*(s+2));
}
ans: 12 6 11
12.
main()
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);
}
ans: u,
ets and Brickbats,
Bouquets and
Brickbats,
u
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);
main()
{
int a=10,b=20;
a>=5?b=100:b=200;
printf("%d\n",b);
}
}
ans: Bangalore
Delhi
Delhi
main()
{
char *p = "hello world!";
p[0] = 'H';
printf("%s",p);
}
ans: Hello world
18.
main()
{
{
int x=1,y=1;
while( (x > 0) && (y > 0) )
{
printf("%16d%16d",x,y);
x += y;
y += x;
}
}
printf("%s", ++*cp);
printf("%s",--*++cp);
}
ans: lvalue required for
second printf statement
19.
23.
24.
while( s <=
ans:
main()
int f(int p)
{
int i = 0, t = 1, s = 1;
p)
i++;
{
int i,j;
for(i=1;i<=5;i++)
{
printf("\n");
for(j=i;j>0;j--)
printf("%d",i);
}
t += 2;
s += s;
}
return i;
}
25.
ans: this function gives
the no. of bits required
while( y > 0 )
{
if( y%2 == 1)
answer = answer * z;
y=y/2;
z=z*z;
}
return answer;
}
to represent a number
in binary form
20.
a sorted array.
21.
recursively.
22.
main()
ans: z power y
26.
27.
28.
write a function
maxsubstring(str,alpha,theta) str is
the source string and have to
return maximum substring which
starts with alpha and ends with
theta.
ans:
main()
{
int i,j=0,k;
char st = 'x';
char en = 'y';
char
p[]="abxabcdyxabcdabcydabcd
xabycd";
char *str;
for(i=0;p[i]!='\0';i++)
{
if(p[i] == st)
break;
}
if(p[i]=='\0')
{
printf("\n starting
character not found\n");
exit(0);
}
str = &p[i];
k=i;
while(p[++i]!='\0')
if(p[i] == en)
j=i;
if(j==0)
printf(" ending
character not found\n");
else
for(;k<=j;k++)
printf("%c",*str++);
}
29.
How do you write a program which
produces its own source code as its
output?
How can I find the day of the week
given the date?
Why doesn't C have nested
functions?
What is the most efficient way to
count the number of bits which are set in a
value?
ans: K. Ritchie
How can I convert integers to
binary or hexadecimal?
ans: K. Ritchie
How can I call a function, given its
name as a string?
ans: function pointers
How do I access command-line
arguments?
How can I return multiple values
from a function?
ans: using pointer or structures
How can I invoke another program
from within a C program?
ans: using system function
How can I access memory located
at a certain address?
How can I allocate arrays or
structures bigger than 64K?
How can I find out how much
memory is available?
{
int x=20,y=35;
x = y++ + x++;
y = ++y + ++x;
printf("%d %d\n",x,y);
}
ans: 57 94
33.
30.
main()
main()
{
char *p1="Name";
char *p2;
p2=(char *)malloc(20);
while(*p2++=*p1++);
printf("%s\n",p2);
}
{
int x=10,y=15;
x=x++;
y=++y;
printf("%d %d\n",x,y);
}
ans: 11 16
31.
int x;
main()
{
int x=0;
{
int x=10;
x++;
change_value(x);
x++;
Modify_value();
printf("First output:
{
char *p1="Name";
char *p2,*p3;
p2=(char *)malloc(20);
p3=p2;
while(*p2++=*p1++);
printf("%s\n",p3);
}
%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);
}
ans:
First output : 12
Second output : 1
Third output : 1
32.
main()
34.
main()
{
int x=5;
printf("%d %d
%d\n",x,x<<2,x>>2);
}
ans: 5 20 1
35.
#define swap1(a,b) a=a+b;b=ab;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;
}
main()
{
int a=1,b=2,c=3;
printf("%d,%d",a,b,c);
}
ans:
10 5
10 5
ans: 1, 2
41.
36.
main()
{
struct
{
char a[3];
int b;
}x;
char *cp;
printf(%d
%d,sizeof(cp),sizeof(x));
}
main()
{ char *ptr = "Ramco
Systems";
(*ptr)++;
printf("%s\n",ptr);
ptr++;
printf("%s\n",ptr);
}
ans:
Samco Systems
amco Systems
37.
main()
{ char s1[]="Ramco";
char s2[]="Systems";
s1=s2;
printf("%s",s1);
}
42.
main()
{
int p=3,q=4;
q = shw(&p);
printf("%d %d",p,q);
}
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: 10 garbage
43.
ans: (x<<3-x)
44.
ans: RamcoSystems
(Note: <malloc.h>
should be included)
39.
main()
{
char *s1 = "hello",*s2
="abce";
strcpy(s1,"");
s2[0] = s1[0];
printf("%d
%d",strlen(s1),strlen(s2));
}
ans: 0 0
45.
t=p[i];
p[i]=p[j-i];
p[j-i]=t;
}
printf("%s",p);
}
main()
{
int i=10;
printf("%d%d%d",i,i++,+
+i);
}
ans: 12 11 11 (compiler
dependent)
49.
46.
{
int i=10;
printf("%d %d %d",i,++i,i+
+);
}
const char *
char * const
What is the differnce between the
above two?
ans: const char *
pointer
to a constant character
char * const
constant
pointer pointing to a character
47.
main()
ans: 12 12 10 (compiler
dependent)
50.
main()
{
void f(int,int);
int i=10;
f(i,i++);
}
void f(int i,int j)
{
if(i>50)
return;
i+=j;
f(i,j);
printf("%d,",i);
}
main()
{
char *x="new";
char *y="dictonary";
char *t;
void swap (char * , char *);
swap (x,y);
printf("(%s, %s)",x,y);
char *t;
t=x;
x=y;
y=t;
printf("-(%s, %s)",x,y);
}
void swap (char *x,char *y)
{
char *t;
y=x;
x=y;
y=t;
}
ans: 51 41 31 21 (i=11,
j=10 for function f)
51.
main()
{
void f(int,int);
int i=10;
f(i,++i);
}
void f(int i,int j)
{
if(i>50)
return;
i+=j;
f(i,j);
printf("%d,",i);
}
ans: multiple
declaration of t and all
declarations should be
before executable
statement(errors)
48.
main()
{
char p[]="string";
char t;
int i,j;
for(i=0,j=strlen(p);i<j;i++)
{
ans: 55 44 33 22 (i=11,
j=11 for function f)
52.
main()
{
char *s="hello world";
int i=7;
printf("%.*s",i,s);
}
ans: hello w
53.
char
(*x)[]
main()
char
*x[]
function returning pointer to int,
char etc.,
ans: int *x()
char *x()
char (*x)
()
54.
main()
{
union{
int x;
char y;
struct {
char x;
char y;
int xy;}p;
}q;
printf("\n %d,
%d",sizeof(q),sizeof(int));
}
{
enum number { a=-1, b=
4,c,d,e};
printf("%d",e);
}
ans: 4,2
55.
main()
{
char *x="String";
char y[] = "add";
char *z;
z=(char *) malloc(sizeof(x)
+sizeof(y)=1);
strcpy(z,y);
strcat(z,x);
printf("%s+%s=%s",y,x,z);
}
ans: Lvalue required
56.
main()
ans: 7
58.
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);
}
}
()
pointer to array of int, char etc.,
this is array pointer
59.
main()
{
int i, count, x=1;
for(i=0, count=0;i<16;i++)
if( !(x&(1<<i)) )
count++;
printf("%d",count);
}
main()
{
int i, count, x=1;
for(i=0, count=0;i<16;i++)
if(x&(1<<i) )
count++;
printf("%d",count);
}
main()
main() main()
{{
int fact; int fact=0
long int x; for(i=1;i<=n;i++)
fact=factoral(x); fact=fact*i;
}}
int factorial(long int x)
{
if(x>1) return(x*factorial(x-1);
}
{
int x, *y;
x = y;
printf(%d,x);
}
ans: nonportable
pointer conversion
66.
main()
ans: 34
67.
{
char str[5]="hello";
if(str==NULL) printf("string
null");
else printf("string not
null");
}
{
char a[10]="hello";
strcpy(a,'\0');
printf("%s",a);
}
ans: arguments must be
a string constant or
character array variable
here it is constat
character not a string
constant. Hence
program error
main()
68.
char a[5][15];
int b[5][15];
address of a 0x1000 and b is
0x2000 find address of a[3][4] and
b[3][4]
69.
p = &val;
}
main()
{
int i=10;
printf("i=%d\n", i);
fn(&i);
printf("i=%d\n", i);
}
ans: i=10
i=10
74.
ans: K.Ritchie
70.
x = x+y;
y = x-y;
x = x-y;
main()
{
a=2;
b=3;
x=SUM(a,b)*2;
printf("x=%d\n",x);
}
x = x^y;
y = x^y;
x = x^y;
x = x*y;
y = x/y;
x = x/y;
ans: 8
71.
number(int i)
{
number++;
printf("%d\n",number);
}
75.
main()
{
static int i=0;
number(i);
}
Code 1 :
for(i=0; i<1000; i++)
for(j=0; j<100; j++)
x = y;
Code 2 :
for(i=0; i<100; i++)
for(j=0; j<1000; j++)
x = y;
Which code will execute faster
ans: Code2
(Code 1 =
1,01000 increment operations)
(Code 2 =
1,00100 increment operations)
main()
{
unsigned char i;
int sum;
for(i=0; i<300; i++)
sum+ = i;
printf("\nSum = %d\n",
sum);
}
76.
main()
{
int a[10] = {1, 2, 3, 4, 5, 6,
7, 8, 9, 10}, i, x=10, temp;
for(i=0; i<x; i++){
temp = a[i];
a[i] = a[x-i-1];
a[x-i-1] = temp;
}
main(0
{
int i = 1;
fork();
fork();
printf("\ni = %d\n", i+1);
}
ans: 4 printfs will occur
and i = 2
78.
char a[5]="hello";
printf("%s",a);
}
ans: array size is small
it should be 6
83.
main()
{
unsigned int x=-1;
int y;
y = ~0;
if(x == y)
printf("same");
else
printf("not same");
}
ans: m = 2, n = 3
84.
79.
main()
{
int i=10;
fork();
fork();
fork();
printf("%d,i);
}
main()
{
char *g="string";
strcpy(gxxx(),g);
g = gxxx();
strcpy(g,"oldstring");
printf("The string is : %s",gxxx());
}
char *gxxx()
{
static char xxx[1024];
return xxx;
}
main()
{
int m;
m=2*f(3,g(4,5));
printf("\n m is %d",m);
}
85.
ans: m is 26
81.
main()
{
char a[10];
strcpy(a,"\0");
if (a==NULL)
printf("\a is null");
else
printf("\n a is not null");
}
ans: a is not null
82.
main()
{
Oldstring
86.
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");
}
93.
89.
ans: 2
91.
char *f();
main()
{
char*a,*f();
a=(char*)malloc(20*sizeof(char));
a=f();
printf("%s",a);
}
char *f()
{static char n[20];
strcpy(n,"Hello World");
return(n);
}
main()
{
int d ;
int i=10;
d =sizeof(++i);
printf("%d",d);
}
94.
88.
51
9 56
6 160
7 30 32
9 56 1120
main()
{
int i=7;
i = i++*i++;
printf("%d\n",i);
i=7;
95.
char *f();
main()
{
char*a,*f();
a=(char*)malloc(20*sizeof(char));
a=f();
printf("%s",a);
}
char *f()
{char n[20];
strcpy(n,"Hello World");
return(n);
}
ans: unpredictable
output. auto variable
address should not be
returned. It will lose its
scope when it comes out
of the block.
96.
char *f()
main()
{
char *a,*f();
a=f();
printf("%s",a);
}
char *f()
{return("Hello World");}
variable or a string
constant. Instead of !
give !
100.
101.
main()
{
int i;
if(i=0)
printf(" Hell ");
else
printf("Heaven");
}
ans: Heaven
102.
{
int i,j;
for(i=0,j=0;i<5,j<25;i+
+,j++);
printf("%d %d",i,j);
}
ans: 25 25 A pair of
expressions separated
by a comma is
evaluated left to right,
and the type and value
of the result are the
type and value of the
right operand. Here
weve to consider j<25
condition.
which is valid :
(i)char arr[10];
arr="hello";
(ii) char arr[]="hello";
ans: second is correct. In first
lvalue required.
99.
main()
{
char *str;
str=(char*)malloc(20*sizeof(char));
strcpy(str,"test");
strcat(str,'!');
printf("%s",str);
}
ans: strcpy function
arguments should be
either a character array
main()
103.
1)pointer to a function.
2)pointer to structure.
3)static variable and difference
b/w(const char *p,char const
*p,const char* const p).
4)pass by value & reference.
5)string library functions(syntax).
6)Write a program to compare two
strings without using the strcmp()
function.
7)Write a program to concatenate
two strings.
8)Write a program to interchange 2
variables without using the third
one.
9)Write programs for String
Reversal & Palindrome check .
109.
{
int yr;
int day;
int month;
} date1,date2;
date1.yr = 2004;
date1.day = 4;
date1.month = 12;
now how will you
initialize date2
(without member
by member
assignment)
ans: date2 =
date1;
110.
main()
{
char str[]={"hell"};
int i;
for(i=0;i<5;i++)
printf("%c%c%c
%c\n",str[i],i[str],*(str+i),*(i+str));
}
ans:
hhhh
eeee
llll
llll
106.
107.
main()
{
int i = 10;
int j = i >> 10;
printf("%d",j);
}
ans: 0
108.
main()
{
extern int a;
printf("%d",a);;
}
int a=20;
ans: 20
111.
105.
struct Date
main()
{
int a[5]={2,3};
printf("\n %d %d
%d",a[2],a[3],a[4]);
}
ans: 0 0 0 if there are
fewer initializers uninitialized
variables are zero
112.
main()
{
inti=-3,j=2,k=0,m;
m=++i&&++j||++k;
printf("\n %d %d %d
%d",i,j,k,m);
}
ans: -2 3 0 1
113.
main()
{
int a,b;
a=sumdig(123);
b=sumdig(123);
printf("%d %d",a,b);
}
sumdig(int n)
{
static int s=0;
int d;
if(n!=0)
{
d=n%10;
n=(n-d)/10;
s=s+d;
sumdig(n);
}
else return(s);
}
char str[5]="fast";
static char *ptr_to_array =
str;
printf("%s",ptr_to_array);
}
ans: error. for auto
variables initializers can
be function calls or
some expressions. But
for static initializers
should constants or
constant expressions.
ans: 6 12
114.
119.
main()
{
char str[5]="fast";
char *ptr_to_array = str;
printf("%s",ptr_to_array);
}
ans: 27 6
115.
main()
{
const int x=get();
printf("%d",x);
}
get()
{
return(20);
}
ans: 20 for auto
variables initializers can
be function calls or
some expressions. But
for static initializers
should constants or
constant expressions.
120.
main()
{
int i=10;
fn(i);
printf("%d",i);
}
fn(int i)
{
return ++i;
}
116.
A function has this prototype void
f1(int **x), How will you call this function?
{a) int **a;
(b) int a;
(c) int
*a;
(d) int a=5;
f1(a); f1(&a); f1(&a); f1(&&a);
ans: int *a; f1(&a);
117.
121.
main()
{
int i,j;
i=10;
j=sizeof(++i);
printf("%d",i);
}
main()
{
int l=1;
for(;;)
{
printf("%d",l++);
if(l>10)
break;
}
}
ans: 12345678910
118.
ans: 10
main()
{
ans: 10
122.
main()
{
struct emp
{
char name[20];
int age;
float sal;
};
struct emp e = {"tiger"};
printf("\n %d
%f",e.age,e.sal);
}
ans: 0 0.000000 If there
are fewer initializers in
the list than members of
the structure the
trailing members are
initialized with zero.
There may not be more
initializers than
members.
123.
main()
{
char *pDestn,*pSource="I
Love You Daddy";
pDestn=(char
*)malloc(strlen(pSource));
strcpy(pDestn,pSource);
printf("%s",pDestn);
free(pDestn);
}
ans: I Love You Daddy
128.
{
char i=0;
for(;i>=0;i++) ;
printf("%d\n",i);
}
ans: error(multiple
declaration for BAD)
125.
main()
{
char a[5][5],flag;
a[0][0]='A';
flag=((a==*a)&&(*a==a[0]));
printf("%d\n",flag);
}
ans: -128
124.
typedef enum
grade{GOOD,BAD,WORST,}BAD;
main()
{
BAD g1;
g1=1;
printf("%d",g1);
}
main(0
ans: 1
129.
main()
{
int i=5,j=5,k;
k=++i+++j;
printf("%d",k);
}
ans: lvalue required (+
+i++)
130.
main()
{
int b=10;
int *p=&b;
*p++;
printf("%d",*p);
}
ans: unknown value
(value at memory
location next to the
memory location of b
ans: -1 -1
126.
#ifdef TRUE
int I=0;
#endif
main()
{
int j=0;
printf("%d %d\n",i,j);
}
131.
main()
{
int i=0,j=50
while (i<j)
{
if(<some condtn>)
{
<body of the loop>
i++
}
elseif(<some condtn>)
10 10 11 12 13
14 15 16 17 18
19
135.
main()
{
int a[]={5,4,3,2,1};
int x,y;
int *p=&a[2];
*p++;
x=++*p;
y=*(p++);
printf("%d %d",x,y);
}
main()
{
int a[20],i;
for(i=0;i<20;i++)
{
a[i]=i;
}
for(i=0;i<20;i++)
{
a[i]=a[20-i];
}
for(i=0;i<20;i++)
printf("%d",a[i]);
}
ans: unknown
value 19 18 17
16 15 14 13 12
11 10 11 12 13
14 15 16 17 18
19
134.
136.
ans: 3 3
137.
int a;
scanf("%f",&a); is there any error
or warning ?
ans. no compile time error but
run time error
138.
main()
{int *p,*q;
p=(int *)1000;
q=(int *)2000;
printf("%d",(q-p));
}
main()
{
int a[20],i;
for(i=0;i<20;i++)
{
a[i]=i;
}
for(i=0;i<20;i++)
{
a[i]=a[20-i];
}
for(i=0;i<20;i++)
printf("%d",a[i]);
}
ans: 19 18 17 16
15 14 13 12 11
ans: 500
139.
140.
main()
{
extern int a;
a=10;
printf("%d",a);
}
int a=20;
switch(n)
case 1:printf("CASE !");
case(2):printf("default");
break;
}
ans: 10
141.
main()
main()
{
int i = 2;
printf("%d %d %d %d ",i, i+
+,i--,i++);
}
ans: 3 2 3 2
143.
main()
{
int i = 2;
printf("%old %old %old
%old ",i, i++,i--,i++);
}
ans: 3ld 2ld 3ld 2ld
144.
149.
(b)
main()
{
int i=0,a[20],*ptr;
ptr=a;
while(min(ptr+
+,&a[9])<&a[8])
i=i+1;
printf("i=%d\n",i);
}
ans: i=5
150.
~(~0<<8)?
ans: Last 8 digits are 1's
rest are 0's.
151.
ans: File
145.
main()
{
printf(" Hello \o is the world
");
}
ans: Hello o is the world
146.
What is
int *p(char (*s)[])
ans: p is a function
which is returning a
pointer to integer
which takes arguments
as pointer to array of
characters.
147.
struct x
{
int I;
char s;
};
union
{
struct x y;
double j;
}z;
main()
{
printf("%d",sizeof (z));
}
ans: 8
152.
main()
{
char
a[]={'1','2','3',0,'1','2','3'};
printf("%s",a);
}
ans: 123
ans: implement strstr
function
148.
main()
{
int n = 1;
153.
main()
{
int
a[]={'1','2','3',0,'1','2','3'};
printf("%s",a);
{.}}
printf(%u%u%u
%u,a,*a,**a,***a);
ans: 1
154.
main()
{
#define x 10
{
printf("%d",x);
}
}
main()
ans: 10
155.
{
int a[2][2]={{2},{3}};
printf("%d ",a[0][0]);
printf("%d ",a[0][1]);
printf("%d ",a[1][0]);
printf("%d ",a[1][1]);
}
main()
{
#define x 10
{
printf("%d",++x);
}
}
ans: lvalue required
156.
162.
main()
{
char a[]="ABCDEFGH";
printf("%d",sizeof(a));
}
ans: 9
157.
ans: 2 0 3 0
main()
{
int i=(int*)0x1000;
printf("%d",i);
}
ans: nonportable
pointer conversion
158.
char str1[]="hello";
char str2[]="hello";
the conditional string test
(str1==str2)
returns FALSE
ans: use strcmp
function
164.
main()
{
int i;
char *str4="123four";
i=atoi(str4);
printf("%d",i);
}
main(int I)
{
printf("%d",I);
}
ans: 1 (command line
arguments)
159.
main()
{
printf("
%d",printf("helloworld"));
}
ans: helloworld 10
160.
main()
{
int a[2][2][6]
{{2,3,4,5,6,7}
ans: 123
165.
main()
{
char loop;
for(loop='A';loop<='z';loop++)
printf("%c",loop);
}
166.
main()
ans: 5 20 1
{
char
s[]={'1','2','3',0,'1','2','3'};
printf("%s",s);
}
ans: 123
167.
174.
main()
{
int a[2][2]={2,3};
printf("%d %d %d %d",a[0]
[0],a[0][1],a[1][0],a[1][1]);
}
main()
ans: 2 3 0 0
{
char *p=Caritor;
*++p;
printf(%s,p);
*++p;
printf(%s,*p);
}
175.
main()
{
int i=-3,j=2,k=0,m;
m= ++j&&++i&&++k;
printf("%d %d %d
%d",i,j,k,m);
}
main()
ans: printf(\%);
{
const int i=7;
printf("%d",++i);
}
169.
What is the max no of char in
command line arguments?
ans:
170.
arithmetic Operation cant be
performed on void pointers.
171.
177.
main()
{
char str1[]="HELLO";
char str2[]="HELLO";
if(str1==str2)
printf("EQUAL");
else
printf("NOT EQUAL");
}
main()
{
int a[2][3]
[4]={{1,2,3,4,5,6,7,8,9,1,1,2},
{2,3,4,7,6,7,8,9,0,0,0,0}};
printf("%d %d %d
%d",a,*a,**a,***a);
}
main()
{
int s=5;
printf("%d",s,s<<2,s>>2);
}
main()
{
printf("%c",7["sundaram"]);
}
ans: 5
173.
main()
{
int s=5;
printf("%d %d
%d",s,s<<2,s>>2);
}
main()
{
printf("%c","sundaram"[7]);
}
ans: m (a[i], i[a], a[2],
2[a])
181.
{
printf("%d %d",sizeof
(struct x),sizeof (struct y));
}
182.
};
main()
main()
{
int k=2,j=3,p=0;
p=(k,j,p);
printf("%d\n",p);
}
main()
{
printf("%d",-1>>4);
}
struct x
{
int i;
char c;
};
186.
main()
{
int i=-10;
for(;i;printf("%d\n",i++));
}
ans: prints -10 to -1
187.
main()
{
unsigned int i=-1;
printf("%d %u\n",i,i);
printf("%u\n",i*-1);
}
union y{
struct x a;
double d;
};
main()
{
printf("%d",sizeof(union
ans:
-1 65535
1
y));
}
188.
main()
{
int **i;
int *j=0;
i=&j;
if (NULL != i&& NULL != *i)
{
printf("I am here");
}
}
ans: 8 (union y is a
kunion variable type.
Sizeof operator takes
input either a variable
or a data type)
184.
struct x{
char c1;
char c2;
int i;
short int j;
};
struct y{
short int j;
char c1;
char c2;
int i;
main()
{
int *j=(int *)0x1000;
printf("%p",j);
}
196.
struct x
{
int i=0; /*line A*/
};
main()
{
struct x y; /*line B*/
}
main()
{
int *j=0x1000;
printf("%p",j);
}
ans: 0000:1000
191.
main()
{
int *j=(int *)0x1000; (or)
197.
int *j=0x1000;
printf("%d",j);
}
struct {
int len;
char *str
}*p;
++p -> len
ans: 4096
ans: increments len
192.
main(int x)
{
printf("%d",x);
}
198.
main()
{
char
a[]="abcdefghijklmnopqrstuvwxyz"
;
printf("%d",sizeof(a));
}
main()
{
char
a[]={'1','2','3',0,'1','2','3'};
printf(a);
}
main()
{
char
a[]="abcdefghijklmnopqrstuvwxyz";
char *p=a;
printf("%d ",strlen(p));
p+=10;
printf("%d",strlen(a));
}
ans: 123
ans: 26 26
194.
200.
main()
{
printf("%d",printf(" hello
world "));
}
main()
{
int a[]={5,6};
printf("%d",a[1.6]);
}
ans: 6
201.
int a[2][3][4]={
{2,1,4,3,6,5,8,7,0,9,2,2},
{1,2,3,4,5,6,7,8,9,0,1,2}
};
printf("%u %u %u
%u",a,*a,**a,***a);
}
ans:
5364875,5364875,5364875,2
202.
{
unsigned short a=-1;
unsigned char b=a;
printf("%u%d ",a,b);
}
main()
{
char a =0xAA ;
int b ;
b = (int) a ;
b = b >> 4 ;
printf("%x",b);
}
ans: fffa
203.
203.
204.
main()
#define maxval 5
main()
{
int i=1;
if(i-maxval)
{
printf("inside");
}
else
{
printf("out");
}
}
ans: inside
209.
main()
{
int a;
#define a 3+3
#define b 11-3
main()
{
printf("%d",a*b);
}
printf("%d",scanf("%d",&a));
}
ans: 33
210.
main()
{
printf("as");
printf("\bhi");
printf("is\n");
}
ans: ahiis (\b is
backspace. So s is erased)
{
int *i;
int s=(int
*)malloc(10*sizeof(int));
for (i=0;i<10;i++)
{
printf("%d",i*i);
}
}
ans: error (Nonportable
pointer conversion and illegal use
pointer i*i)
211.
206.
main()
{
main()
}
ans: 2 1
ans:1076
212.
218.
219.
void main()
{
int d=5;
printf("%f",d);
}
int a[5,6]
how much memory will be
allocated
ans: doubt(if comma
operator is considered 12 bytes
will be allocated)
213.
#define d 10+10
main()
{
printf("%d",d*d);
}
ans: 120
214.
main()
{
int i,j=1;
for(i=0;i<10;i++);
{
j=j+i;
}
printf("%d %d",i,j);
}
ans: 10 11
215.
216.
main()
{
int i=0xaa;
char *p;
p=(char *)i;
p=p>>4;
printf("%x",p);
}
ans: illegal use of
pointer p=p>>4
217.
main()
{
enum{sunday=1,monday,wednesday};
printf("%d
%d",sizeof(wednesday),wednesday
);
ans: undefined
220.
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);
to char */
typedef fpc *pfpc; /*
pointer to above */
typedef pfpc fpfpc(); /*
function returning... */
typedef fpfpc *pfpfpc; /*
pointer to... */
pfpfpc a[N];
/* array
of... */
ans: 1234
221.
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: 123
222.
void main()
{
char *s="\12345s\n";
printf("%d",sizeof(s));
}
ans: 4 (pointer takes 4
bytes here)
223.
void main()
{
unsigned i=1; /* unsigned
char k= -1 => k=255; */
signed j=-1; /* 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");
}
225.
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: 1 garbage garbage
1 2 garabage 1 2 3
226.
void main()
{
int
count=10,*temp,sum=0;
temp=&count;
*temp=20;
temp=∑
*temp=count;
printf("%d %d %d
",count,*temp,sum);
}
ans: 20 20 20
227.
{
static i=3;
printf("%d",i--);
return i>0 ? main():0;
}
ans: less
224.
main()
ans: 321
228.
char *foo()
{
char result[100];
strcpy(result,"anything is
good");
return(result);
}
void main()
{
char *j;
j=foo();
printf("%s",j);
}
ans: anything is good
(address of auto
variable should not be
returned. Sometimes it
will give unknown
results)
void main()
{
char
*s[]={ "dharma","hewlettpackard","siemens","ibm"};
har **p;
p=s;
printf("%s ",++*p);
printf("%s ",*p++);
printf("%s ",++*p);
}
main()
{
int i=3,j=5;
while (i--,j--)
{
printf("%d %d \n",i,j);
}
}
229.
ans:
be executed
234.
main()
ans: 1 2 3 4 5
231.
{
int i=3,j=5;
if(i--,j--)
printf("%d %d \n",i,j);
}
main()
{
static int i = 0;
int z;
if(i++<5)
{
printf("%d ",i);
}
else
exit(0);
z=3;
printf("%d %d ",z,main());
}
24
13
02
-1 1
-2 0
5 times loop will
ans: 2 4
235.
main()
{
int i=3;
printf("%d %d %d ",+
+i,i--,i+=5);
}
ans: 8 8 8
236.
main()
{
int times =5;
int i=3;
int j=4;
int k=34;
i=j+k;
while(times --)
{
i=times;
j=times;
k=times;
}
printf("%d %d %d ",i,j,k);
}
main()
{
static int i = 0;
int z;
if(i++>5)
{
printf("%d ",i);
exit(0);
}
z=3;
printf("%d %d ",z,main());
}
ans: 7
ans: 0 0 0
232.
main()
{
int z=3;
printf("%d %d &",z,main());
}
237.
main()
{
int num =32765;
while (num++);
printf(%d ,num);
}
case 1:i+=2;
case 5:i+=5;
default: i+=4;
break;}
printf("%d,",i);
}
}
ans: 1
238.
main()
{
float k=3.4156;
printf("%f %f
",floor(k),ceil(k));
}
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");
}
main()
{
int number =25;
char name ='A';
printf("The addition of the
name and the number is %o
",name+number);
}
ans: The addition of the
name and the number is 132
240.
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;
}
ans: change everywhere
a to *a and b to *b
241.
{
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");
}
int main()
{
FILE *fp;
fp=fopen("test.dat","w");
fprintf(fp,'hello\n");
fclose(fp);
fp=fopen ("test.dat","w");
fprintf (fp, "world");
fclose(fp);
return 0;
}
If text.dat file is already present
after compiling and execution how
many bytes does the file occupy ?
ans: 5 bytes
242.
main()
main()
{
int i;
for(i=0;i<20;i++)
{
switch(i)
{
case 0:i+=5;
void main()
{
int i;
char a[]="String";
strcpy(g,"Oldstring");
printf("The string is %s",g);
}
ans: The string is
Oldstring
p = malloc(strlen(Temp) +
1);
249.
main()
strcpy(p,Temp);
printf("(%s, %s)",a,p);
free(p);
free(a);
} /*Line number 15*/
{
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");
}
}
main()
{
unsigned int x=-1;
int y;
y = ~0;
if(x == y)
printf("same");
else
printf("not same");
}
ans: same
247.
char *gxxx()
{
static char xxx[1024];
return xxx;
}
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");
}
}
main()
{
char *g="string";
strcpy(gxxx(),g);
g = gxxx();
strcpy(g,"oldstring");
printf("The string is :
%s",gxxx());
}
ans: The string is
oldstring
248.
main()
{
printf("%u",main);
}
{
int x,a=8,b=6;
x=find(a,find(a,b));
printf("%d",x);
}
ans: 0
252.
main()
find(int x,int y)
{ return ((x<y)?0:(x-y));}
{
printf("%p",main);
}
ans: starting address of
main function x:y
(segment : offset). Each
time u run starting
address will change.
Function name always
gives starting address
of that function.
ans: 6
257.
main()
{
int a;
if (a=7)
printf(" a is 7 ");
else
printf("a is not 7");
}
main()
{
printf("%u",main());
}
ans: a is 7
258.
main()
{
int a=4,b=3,c=5;
if (a>b)
if(b>c)
printf("inner");
else printf("outer");
}
main()
{
int i=10;
printf("%d %d %d",i,i++,+
main()
+i);
{
int a=2,b=3,c=5;
if (a>b)
if(b>c)
printf("inner");
else printf("outer");
}
}
ans: 12 11 11 (compiler
dependent)
254.
main()
{
int *p,*q;
p=(int *)1000;
q=(int *)2000;
printf("%d",(q-p));
}
main()
{
inc(); inc(); inc();
}
inc()
{
static int x;
printf("%d", ++x);
}
ans: 500
255.
find(int x,int y)
{return ((x<y)?0:(x-y)):}
find(a,find(a,b)) is used for?
ans: find out minimum
of a, b
ans: 123
261.
256.
main()
{
printf("%d", strlen(""));
main()
268.
main()
{
printf("%d", sizeof(""));
}
{
char line[80];
scanf("%[^a]",line);
printf("%s",line);
}
main()
{
int a=5,b=2;
printf("%d", a+++b);
}
269.
main()
{
char line[80];
scanf("%[^u]",line);
printf("%s",line);
}
ans: 7
264.
main()
{
int v=3, *pv=&v;
printf(" %d %d ", v,*pv);
}
main()
ans: 3 3
265.
main()
{
printf("%f %f",floor(2.8),ceil(-2.8));
{
enum
cities{bethlehem,jericho,nazareth=1,jerusa
lem};
printf("%d
%d",jericho,nazareth);
}
}
ans: -3.000000
-2.000000
271.
ans: 1 1
int x[3][4] ={
{1,2,3},
{4,5,6},
{7,8,9}
}
266.
difference between scanf and
sscanf function
ans: sscanf(s,...) is
equivalent to scanf(...)
except that
input charecter are
taken from string s.
267.
main ()
{
int i =5;
i= (++i)/(i++);
printf( "%d" , i);
}
main()
{
char line[80];
scanf("%[^\n]",line);
printf("%s",line);
}
ans: if you type this is
manu<enter> output
will be this is manu
scanf normally takes a
single string but if we
ans: 2
273.
main()
{
int a,b;
int *p,*q;
a=10;b=19;
p=&(a+b);
q=&max;
}
main()
{
printf("%u", sizeof(func));
}
func()
{
return 0;
}
ans: error (sizeof
operator operand
should not be function
name)
275.
#define max 10
main()
{
int a,b;
int *p,*q;
a=10;b=19;
p=&(a+b);
q=&max;
}
ans: error (must take
address of a memory
location)
280.
main()
{
int i;
printf("%d", &i)+1;
scanf("%d", i)-1;
}
main()
{
printf("%u", sizeof(func()));
}
func()
{
return 0;
}
ans: 2 (sizeof operator
operand should not be
function name but it can
be a function call)
281.
276.
277.
main()
{
int i;
float *pf;
pf = (float *)&i;
*pf = 100.00;
printf("%d", i);
}
main()
{
int n,i=1;
switch(n)
{
case 1:
printf("1");
case 2:
printf("2");
default:
i=10;
}
printf("i=%d",i);
}
ans: 10 (since n is not
initialized it contains
282.
main()
{
int i = 0xff;
printf("%d", i<<2);
}
ans: 1020
283.
#define SQR(x) x * x
main()
{
printf("%d", 225/SQR(15));
}
ans: 225
284.
union u
287.
main()
{
struct st
{
int i : 4;
int j : 4;
int k : 4;
int l;
}st;
int i;
}u;
{
int (*functable[2])(char
*format, ...) ={printf,
scanf};
int i = 100;
(*functable[0])("%d, ", i);
(*functable[1])("%d",
&i);
(*functable[1])("%d",
&i);
(*functable[0])(", %d", &i);
}
main()
{
u.i = 100;
printf("%d, %d, %d",u.i,
u.st.i, u.st.l);
}n
ans: 100 4 0
285.
union x
288.
main()
{
union u
{
int i;
int j;
}a[10];
int b[10];
}u;
{
int i, j, *p;
i = 25;
j = 100;
p = &i; /* Address of i is
assigned to pointer p */
printf("%f", i/(*p)); /* i is
divided by pointer p */
}
{
printf("%d ", sizeof(u));
printf("%d ", sizeof(u.a));
printf("%d",
sizeof(u.a[0].i));
}
main()
289.
main()
{
char *p = "hello world";
p[0] = 'H';
printf("%s", p);
}
ans: 20 20 2 (Note:
when unions or
structures are nested
inner and outer
tagnames should be
different)
286.
main()
{
int (*functable[2])(char
*format, ...) ={printf,
scanf};
int i = 100;
(*functable[0])("%d ", i);
(*functable[1])("%d ", i);
(*functable[1])("%d ", i);
(*functable[0])("%d", &i);
}
ans: runtime error (& is
missing)
main()
{
char * strA;
char * strB = "I am OK";
memcpy( strA, strB, 6);
}
ans: error (pointer
should be initialized
before using)
291.
292.
main()
char *pAddress;
};
{
printf("\% ");
printf("\\% ");
printf("%% ");
printf("\%%");
}
main()
{
struct Foo *obj =
malloc(sizeof(struct Foo));
obj->pName =
malloc(100);
obj->pAddress =
malloc(100);
strcpy(obj->pName,"Your
Name");
strcpy(obj->pAddress,
"Your Address");
free(obj);
printf("%s ", obj->pName);
printf("%s", obj>pAddress);
free(obj->pName);
free(obj->pAddress);
}
ans: % \% % %
293.
main()
{
printf("\%d ", 100);
printf("\\% ");
printf("%% ");
printf("\%%");
}
ans: 100 \% % %
294.
295.
{
char *a = "Hello ";
char *b = "World";
printf("%s", stract(a,b));
}
ans: stract function
should be defined or
strcat should be used
298.
main()
{
char *a = "Hello ";
char *b = "World";
printf("%s", strcat(a,b));
}
struct Foo
{
char *pName;
};
main()
ans: HelloWorld
299.
{
struct Foo *obj =
malloc(sizeof(struct Foo));
strcpy(obj->pName,"Your
Name");
printf("%s", obj->pName);
}
ans: runtime error
(Note: pName should be
initialize before using)
296.
main()
struct Foo
{
char *pName;
main()
{
char *a = "";
char *b = "World";
printf("%s", strcpy(a,b));
}
ans: World
300.
c = i;
printf("%d", c);
}
{
int a[10][10];
func1(a);
func2(a);
}
ans: -56
main()
305.
main ()
{
int x = 10;
printf ("x = %d, y = %d",
x,--x++);
}
ans: lvalue required
306.
main()
{
int i =10, j = 20;
printf("%d, %d, ", j-- , --i);
printf("%d, %d", j++ , +
+i);
}
main()
{
printf("%d, %d", sizeof('c'),
sizeof(100));
}
main()
ans: 2, 2
302.
{
int x=5;
for(;x==0;x--)
{
printf("x=%d\n", x--);
}
}
main()
{
int i = 100;
printf("%d",
sizeof(sizeof(i)));
}
ans: no output
ans: 2
308.
303.
main()
int f();
main()
{
int x=5;
for(;x!=0;x--)
{
printf("x=%d ", x--);
}
}
{
int c = 5;
printf("%p %p %d %d",
f,f(),f,f());
}
int f()
{}
ans: segment:offset
segment:offset integer
integer (all are unknown
values. Segment and
offset values of function
address and function
return value. Values of
function address and
function return value)
304.
main()
{
char c;
int i = 456;
main()
{
int x=4;
for(;x==0;x--)
{
printf("x=%d ", x--);
}
}
ans: x=4 x=2
310.
if (!(1&&0))
{
printf("OK I am done.");
}
else
{
printf("OK I am gone.");
}
}
main()
{
int x=5;
{
printf("x=%d", x--);
}
}
ans: x=5
ans: OK I am done
311.
main()
{
unsigned int bit=256;
printf("%d ", bit);
{
unsigned int bit=512;
printf("%d", bit);
}
}
316.
main()
{
if ((1||0) && (0||1))
{
printf("OK I am done.");
}
else
{
printf("OK I am gone."); }
}
main()
ans: OK I am done
{
int i;
for(i=0;i<5;i++)
{
printf("%d ", 1L << i);
}
}
317.
{
signed int bit=512, mBit;
{
mBit = ~bit;
bit = bit & ~bit ;
printf("%d %d", bit, mBit);
}
}
ans: 1 2 4 8 16
313.
main()
{
signed int bit=512, i=5;
for(;i;i--)
{
printf("%d ", bit = (bit >>
(i - (i -1))));
}
}
ans: 0 -513
318.
main()
{
signed int bit=512, i=5;
for(;i;i--)
{
printf("%d ", bit >> (i - (i
-1)));
}
}
ans: 256 256 256 256
256
315.
main()
{
main()
319.
320.
-Dynamic Binding.
-Reduction of Errors.
321.
return p;
}
main()
int *f4()
{
int d,a=5,b=3,c=(a,b);
d=(a,b);
printf("%d %d",c,d);
}
{
int n;
return (&n)
}
ans: f4 is having
problem as it is
returning address of
auto variable.
main()
326.
{
int a=5,b=3,c=a,d;
d=(a,b);
printf("%d %d",c,d);
}
*p+=1
*p++
are these two same?
ans: not same (first one
increments value
pointed by p and second
one increments
pointer)
ans: 5 3
323.
324.
main()
{
int a=5,b=3,c=(a,b),d;
d=(a,b);
printf("%d %d",c,d);
}
327.
ans: 3 3
328.
int num[3];
num[3]=2;
ans: array index
exceeds array bounds
main()
{
int j=4;
for(int i=0;i<5;i++)
{
j++;
++j;
}
printf("%d",j);
}
main()
{
int a=5,b=3,c=(a,b),d;
d=a,b;
printf("%d %d",c,d);
}
ans: 3 5 (from 321 to
324 think about comma
operator)
325.
main()
{
int j=4;
for(int i=0;i<5;i++)
{
j++;
++j;
}
printf("%d",j);
}
int *f2()
{
int *p;
*p=3;
return p;
}
ans: 14
330.
int *f3()
{
int *p;
p=malloc();
main()
{
char s1[20]="hello world";
s1[5]=\0;
printf("%d",strlen(s1));
}
ans: nonportable
pointer conversion
331.
main()
{
float x=1.0,y=2.0,z=3.0;
f(x,y,z);
}
f(float p,float q,float r)
{
printf("%f %f %f",p,q,r);
}
{
char s1[20]="hello world";
s1[5]=\0;
printf("%d",strlen(s1));
}
ans: 5
332.
333.
#define m 10
f();
main()
{
f(m);
}
f(int j) or f(j)
{
printf("%d",j);
}
ans: 10
334.
f();
main()
338.
main()
{
int x=0;
for(;;x++){
if(x==4) break;
continue;
}
printf("%d\n",x);
}
#define m 10.0
f(float);
main()
{
f(m);
}
f(float j)
{
printf("%f",j);
}
ans: 4
339.
main()
{
int i=100;
do
{--i;}while(i>50);
printf("%d\n",i);
}
f();
main()
{
int x=1,y=2,z=3;
f(x,y,z);
}
f(int p,int q,int r)
{
printf("%d %d %d",p,q,r);
}
ans: 1 2 3 (in prototype
we have not given
ans: 50
340.
main()
{
int o;
int m=-14;
int n=6;
o=m%++n;
n+=m++%o;
printf("%d%d%d",m,n,o);
main()
{
int a=1000,b=1000,c;
(long)c=(long)a*b;
printf("%d",c);
}
347.
main( )
{
char a[];
a[0] = 'A';
printf("%c", a[0]);
}
344.
main()
ans: size of a is
unknown
348.
main()
{
int a, *b = &a, **c =&b;
a=4;
** c= 5;
printf("%d",a);
}
{
printf("%d %d
%d",sizeof('3'),sizeof("3"),si
zeof(3));
}
ans: 2 2 2
ans: 5
349.
345.
main()
main( )
{
int i = 1;
if(!i)
printf("Recursive calls are
real pain!");
else
{
i = 0;
printf("Recursive calls are
challenging\n");
main();
}
}
{
printf("%c","abcdefgh"[4]);
}
ans: e
350.
main()
{
int a[ ]={10,20,30,40,50};
char *p;
p=(char *)a;
printf("%d",*((int *)p+4));
}
ans: 50
main()
{
struct emp{
char n[20];
int age;};
struct emp
e1={"david",23};
351.
main()
{
int a[]={10,20,30,40,50};
char *p;
p=(char *)a;
printf("%d %d %d
%d",*p,*(p+1),*(p+2),*(p+
3));
}
ans: 10 0 20 0
}
352.
main()
{
printf("%c",7["sundaram"]);
}
ans: 20
357.
358.
main()
ans: m
353.
#define str(x) #x
#define Xstr(x) str(x)
#define oper multiply
main()
{
char
*opername=Xstr(oper); /*
#multiply i.e.,
multiply
printf("%s",opername);
}
ans: multiply (#,
stringizing operator
allows a formal
argument within a
macro definition to be
converted to a string)
354.
{
int i=3;
i=i++;
printf("%d",i);
}
ans: 4
359.
main()
{
static char a[]="Bombay";
char *b="Bombay";
printf("%d
%d",sizeof(a),sizeof(b));
}
355.
main()
{
int x = 5;
printf("%d %d", x++, +
+x);
return 0;
}
{
int b;
b=f(20);
printf("%d",b);
}
f(int a)
{
a>20 ? return (10):
return (20);
}
ans: 6 6
361.
main()
{
int z = 4;
printf("%d", printf(" %d %d
", z, z));
}
main()
{
int b;
b=f(20);
printf("%d",b);
}
f(int a)
{
return a>20 ? (10): (20);
362.
main()
{
int z = 45;
printf("%d", printf(" %d %d
", z, z));
}
k = k/2;
printf(%f%f , *j, *k);
}
ans: error (pointer
multiplication and
division is illegal)
ans: 45 45 7
363.
main( )
{
int a[ ] = { 10, 20, 30, 40,
50};
int j;
for (j = 0; j < 5; j++)
{
printf("%d", * a);
a++;
}
}
368.
main( )
{
static char s[ ] =
Rendezvous;
printf(%d, *(s+
strlen(s)));
}
ans: 0
369.
main()
{
char **p="Hello";
printf("%c",*p);
}
main()
{
Int n=20, i = 0;
while(n-->0);
i = i+n;
printf("%d",i);
}
ans: H
370.
main()
{
char **p="Hello";
printf("%s",p);
}
ans: -1
365.
main()
{
int i = 0; char ch = A
do {
printf(%c, ch);
} while (i++ <5| | ++ch <
=F);
}
ans: Hello
371.
main()
{
char **p="Hello";
printf("%s",*p); /* (or)
printf(%s,**p); */
}
ans: AAAAAABCDEF
ans: error
366.
372.
main()
{
char **p="Hello";
printf("%c",**p);
}
ans: error
ans: 0
373.
367.
main()
main( )
{
static float a[ ] = { 13.24,
1.5}
float *j, *k;
j = a;
k = a + 2;
j = j * 2;
{
char a[]="Hello";
printf("%c\n",*a++);
}
ans: lvalue required
374.
main()
{
int a=3,b=2,c=1;
static int k= a<b<c-1;
printf("%d",k);
}
if(i)
main();
}
ans: 5 4 3 2 1
379.
main()
{
int a=5,c;
int ptr;
ptr=&a;
c=*ptr * a;
printf("%d,%d",c,a);
}
main()
{
int a=3,b=2,c=1;
int k= a<b<c-1;
printf("%d",k);
}
ans: 0
376.
main()
380.
{
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 ");
}
main()
{
int x=10,y=5,p,q;
p=x>9;
q=x>3&&y!=3;
printf("p=%d q=%d",p,q);
}
ans: p=1 q=1
381.
main()
{
int x=11,y=6,z;
z=x==5||y!=4;
printf("z=%d",z);
}
ans: z=1
382.
377.
{
int i=4;
switch(i)
{
case 1:
printf("HEllo");
case default: // "case"
should not come with
"default"
printf("****");
}
}
ans: error (case should
not be there with
default)
378.
main()
main()
main()
{
static int i=5;
printf("%d ",i--);
{
int c=0,d=5,e=10,a;
a=c>1?d>1||e>1?
100:200:300;
printf("a=%d",a);
}
ans: a=300
383.
main()
{
int i=-5,j=-2;
junk(i,&j);
printf("i=%d,j=%d",i,j);
}
junk(i,j)
int i,*j;
{
i=i*i;
*j=*j**j;
}
ans: i=-5,j=4
384.
#define NO
#define YES
main()
{
int i=5,j;
if(i>5)
j=YES;
else
j=NO;
printf("%d",j);
}
{
int p = -200;
char c;
c = p;
printf("%d %d", c++, ++c);
}
ans: 57 57
390.
#define NO 0
#define YES 1
main()
{
int i=5,j;
if(i>5)
j=YES;
else
j=NO;
printf("%d",j);
}
ans: 0
386.
int a=1;
int ab=4;
int main()
{
int b=3,a=2;
printf("%i*/%i*/
%*/i",a,b,ab);
}
ans: 2*/3*/%*/i
391.
392.
main()
{
int i,j;
j = 10;
i = j++ - j++;
printf("%d %d", i,j);
}
main()
{
int a=0xff;
if(a<<4>>12)
printf("leftist");
else
printf("rightist");
}
ans: 0 12
393.
ans: rightist
387.
{
int j;
for(j=0;j<3;j++)
foo();
}
foo() {
static int i = 10;
i+=10;
printf("%d ",i);
}
main()
{
int i=+1;
while(~i)
printf("vicious circles");
}
ans: infinite loop
388.
389.
main()
main()
ans: 20 30 40
394.
395.
printf("%s\n",str[i++]);
return;
}
{
union {
int a;
int b;
int c;
} u,v;
u.a = 10;
u.b = 20;
printf("%d %d \n",u.a,u.b);
}
main()
400.
main()
{
int i;
for (i=1;i<100; i++)
printf("%d %0x\n",i,i);
}
ans: 20 20
396.
ans: 1 to 99 will be
printed both in decimal
and hexadecimal form
main()
{
char *str = "12345";
printf("%c %c %c\n", *str,
*(str++), *(str++));
}
401.
ans: 3 2 1
397.
struct {
int x;
int y;
union {
int id_no;
char *name;
}b;
}s,*st;
main()
{
st = &s;
st-x=10;
st-b.id_no = 101;
printf("%d
%d\n",s.x,s.b.id_no);
}
main()
{
int len=4;
char *st="12345678";
st = st -len;
printf("%c\n",*st);
}
ans: some junk
character is printed
399.
func();
main()
{
func(1);
}
func(int i)
{
static char *str
={ "One","Two","Three",
"Four"};
402.
main()
{
int j,ans;
j = 4;
ans = count(4);
printf("%d\n",ans);
}
int count(int i)
{
if ( i < 0) return(i);
else
return( count(i-2) +
count(i-1));
}
ans: -18
403.
main()
{
int i=4;
if(i=0)
printf("statement 1");
else
printf("statement 2");
}
ans: 10 -1
408.
ans: statement 2
404.
main()
{
char a[2];
*a[0]=7;
*a[1]=5;
printf("%d",&a[1]-a);
}
409.
{
char
*a[4]={"jaya","mahe","cha
ndra","buchi"};
printf("%d %d
%d",sizeof(a),sizeof(char
*),sizeof(a)/sizeof(char *));
}
main()
{
char a[]="hellow";
char *b="hellow";
char c[5]="hellow";
printf("%s %s %s ",a,b,c);
printf("%d %d
%d",sizeof(a),sizeof(b),size
of(c));
}
ans: 16 4 4 (pointer
takes 4 bytes)
410.
natural numbers is =
n(n+1)/2.
if we subtract
the above sum from
the sum of all the
numbers in the
array , the result is
nothing but the
missing number.
{
char a[]="hellow";
char *b="hellow";
char c[7]="hellow";
printf("%s %s %s ",a,b,c);
printf("%d %d
%d",sizeof(a),sizeof(b),size
of(c));
}
407.
int num[]={10,1,5,22,90};
main()
{
int *p,*q;
int i;
p=num;
q=num+2;
i=*p++;
printf("%d %d",i,p-q);
}
main()
main()
411.
412.
413.
"SEARCH",
"COMPILE"
ans: maximum is 7
(careful about braces
not only in printf but
also in macro definition.
414.
};
char **cp[] = {c+3,c+2,c+1,c};
char ***cpp = cp;
main()
{
printf("%s ", **cpp);
printf("%s", *--*++cpp+3);
printf("%s", *cpp[-2]+3);
printf("%s\n",cpp[-1][1]+1);
}
main()
{
int *p,*q,r;
int values[30];
p=&values[0];
q=values+29;
r=++q-p;
printf("%d",r);
}
ans: 30
419.
415.
static int i = 5;
main()
{
int sum=0;
do
{
sum +=(1/i);
}while(0<i--);
}
struct x
{
int j;
char k[100];
unsigned i;
};
int *ptr1;
struct X *ptr2;
main()
{
printf("%d
%d",sizeof(ptr1),sizeof(ptr2
));
}
enum mode =
{green,red,orange,blue
,white};
main ()
{
green = green +1;
printf("%d,%d",green,red );
}
ans: error (lvalue
required since green is
a symbolic constant and
= operator should not
be there in enum
declaration)
417.
420.
char *c[] ={
"FILE",
"EDIT",
main()
{
int i=5;
printf( " %d %d %d", +
+i,i,i++);
}
ans: 7 6 5
421.
main()
{
int i,j ;
for(i=0;i<=10;i++);
for(j=0;j<=10;j++);
printf("i=%d,j=%d\n",i,j);
}
418.
ans: 4 4
ans: i=11,j=11
422.
ans: 29
423.
main()
{
int p = 0, q =1;
p = q++;
p = ++q;
p = q--;
p = --q;
printf("%d %d",p,q);
}
427.
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: 1 1
424.
main()
{
int a , count;
int func(int);
for (count = 1 ;count
<=5;++count)
{
a = func(count);
printf("%d", a);
}
}
int func(int x)
{
int y;
y=x*x;
return(y);
}
ans: 963852741
428.
{
int n=10;
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: 1491625
425.
main()
{
struct emp{
char emp[];
int empno;
float sal;
};
struct emp member =
{ "TIGER"};
printf(" %d %f",
member.empno,member.s
al);
main()
{
int a[] ={ 1,2,3,4,5,6,7};
char c[] = {'a','x','h','o','k'};
printf("%d %d", (&a[3]&a[0]),(&c[3]- &c[0]));
}
ans: 3 3
426.
main()
main()
{
struct s1 {int i; };
struct s2 {int i; };
struct s1 st1;
struct s2 st2;
st1.i =5;
st2 = st1;
printf(" %d " , st2.i);
}
printf("DONE");
}
case'A':case'B':case'C':case
'D':ch++;continue;
case'E':case'F':ch++;
}
putchar(ch);
}
}
main()
{
int a=2, b=3;
printf(" %d ", a+++b);
}
ans: FG
436.
main()
{
int a=1, b=2, c=3,
*pointer;
pointer=&c;
a=c/*pointer;
b=c;
printf ("a=%d b=%d",a,b);
}
ans: 5
432.
prn(c)
#define max(a,b) (a<b)? b:a
main()
{
int x=1, y=2;
print(max(x++,y),x,y);
print(max(x++,y),x,y);
}
ans: 2 2 2 3 4 2
433.
",int);
ans: 12 6 11 garbage
value
438.
main()
{
int i;
i=1;
i=i+2*i++;
printf("%d",i);
}
ans: 4
435.
main()
{
char ch='A';
while(ch<='F')
{
switch(ch)
{
main()
{
int a=10,b=5, c=3,d=3;
if(a<b)&&(c=d++)
printf("%d %d %d %d"
,a,b,c,d);
else printf("%d %d %d %d",
a,b,c,d);
}
440.
{
char *p1="Name";
char *p2;
p2=(char *)malloc(20);
while(*p2++=*p1++);
printf("%s\n",p2);
}
441.
main()
{
int i=3;
while(i--)
{
int i=100;
i--;
printf("%d..",i);
}
}
446.
main()
{
int x=5;
printf("%d %d
%d\n",x,x<<2,x>>2);
}
ans: 5 20 1
ans: 99..99..99..
447.
442.
main()
{
int rows=3,colums=4;
int a[rows]
[colums]={1,2,3,4,5,6,7,8,
9,10,11,12};
int i, j,k; 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);
}
main()
{
int x=10,y=15;
x=x++;
y=++y;
printf("%d %d\n",x,y);
}
ans: 10 5
10 5 (swap2
wont swap x and y)
448.
main()
{
char *ptr = "Ramco
Systems";
(*ptr)++;
printf("%s\n",ptr);
ptr++;
printf("%s\n",ptr);
}
ans: 11 16
444.
main()
{
int x=20,y=35;
x = y++ + x++;
y = ++y + ++x;
printf("%d %d\n",x,y);
}
ans: 57 94
449.
445.
main()
main()
{
char s1[]="Ramco";
char s2[]="Systems";
s1=s2;
printf("%s",s1);
}
int a[10]={60,57,10,5,4,3,2,8,9};
main()
{
int varx,vary,i;
for (i=0;i<10;i++)
{
if(varx<a[i])
{
vary=varx;
varx=a[1];
}
else if (vary<a[i])
{
varx=vary;
vary=a[i];
}
printf("%d %d
\n",varx,vary);
}
}
main()
{
char *p1;
char *p2;
p1=(char *) malloc(25);
p2=(char *) malloc(25);
strcpy("Ramco",p1);
strcpy(p2,"Systems");
strcat(p1,p2);
printf("%s",p1);
}
ans: RamcoSystems
451.
main()
{
char a[2];
*a[0]=7;
*a[1]=5;
printf("%d",&a[1]-a);
}
main()
{
char a[]="hellow";
char *b="hellow";
char c[5]="hellow";
printf("%s %s %s ",a,b,c);
printf("
",sizeof(a),sizeof(b),sizeof(c
));
}
main()
{
int i=6;
int j;
j=sum(i);
printf("%d",j);
}
sum(int x)
{
int t;
if(x<=1) return (1);
t=sum(x-3)+sum(x-1);
return (t);
}
main()
{
char a[]="hellow";
char *b="hellow";
char c[7]="hellow";
printf("%s %s %s ",a,b,c);
printf("%d %d %d
",sizeof(a),sizeof(b),sizeof(c
));
}
ans: 9
457.
main()
{
int a[]={0,2,4,6,8};
int *ptr;
ptr=a;
printf("%d", *((char *)
ptr+4));
}
ans: 4
458.
main()
ans: d
464.
{
int I=3;
while(I--)
{int I=100;
I--;
printf("%d", I);
}
}
ans: ABC\4
465.
ans: 999999
459.
main()
{
char ch;
for(ch='0';ch<=255;ch++)
printf("%c", ch);
}
void main(void)
{
int a[10], i;
int *b;
b=( int*) malloc(10*
sizeof(int)) ;
*b =&a[3];
for(i=0;i<10;i++)
a[i] =i+10;
printf("%d",b[-1]);
}
x=3
function(++x)...value 4 is passed
to the function
x=3
function(x++)...value 3 is passed
to the function
461.
void main(void)
{
int a[10], i;
int *b;
b=( int*) malloc(10*
sizeof(int)) ;
b =&a[3];
for(i=0;i<10;i++)
a[i] =i+10;
printf("%d",b[-1]);
}
ans: 12
main()
{
int
a[10]={1,2,3,4,5,6,7,8,9,10
};
int *p=a;
int *q=&a[9];
printf("%d",q-p+1);
}
463.
467.
ans: 10
468.
main()
{
int i=6;
int *p=&i;
free(p);
printf("%d",i);
}
ans: 6
469.
main()
{
int i=5;
i=!i>3;
printf("%d",i);
}
ans: 5
475.
ans: 0
470.
471.
{
int a[10];
3[a]=10;
printf("%d",*(a+3));
}
ans: 10
ans: 10
main()
476.
struct emp
{
int a=25;
char b[20]="tgk";
};
main()
{
emp e;
e.a=2;
strcpy(e.b,"tellapalli");
printf("%d %s",e.a,e.b);
}
{
int a=5;
const int *p=&a;
*p=200;
printf("%d",*p);
}
i) (*ptr)++;
ii) *ptr+=1;
iii) *ptr++;
which of the folowing is same.
ans: i) and ii) are same
478.
main()
main()
{
struct t
{
int i;
} a,*p=&a;
p->i=10;
printf("%d",(*p).i);
}
ans: p is array of
pointers that each
points to
a function that takes no
arguments and returns
an int.
472.
void main()
{
char *s="susan";
clrscr();
printf(s);
getch();
}
ans: susan
479.
void main()
{
int a[20];
clrscr();
*a=(int*)malloc(sizeof(a));
printf("%d",sizeof(a));
getch();
}
printf("%d",printf("ABC//"));
}
ans: ABC//5
484.
{
int i=6;
printf("%d",func(i));
}
int func(int r)
{
int static result;
if(r<=0) result=1;
else
result=func(r-3)+func(r-1);
return result;
}
void main()
{
void fun(int,int);
int i ,j;
i=2,j=3;
fun(i++,j++);
printf("%d %d",i,j);
getch();
}
void fun(int i,int j)
{
i++,j++;
}
ans: 13
485.
void main()
{
int ctr=0;
clrscr();
switch(ctr)
{
case 0:
ctr++;
case 1:
ctr++;
default :
ctr++;
};
printf("%d",ctr);
getch();
}
ans: 3
482.
483.
main()
{
main()
{
int i=3;
while(i--)
{
int i=100;
i--;
printf("%d..",i);
}
}
main()
ans: 99..99..99..
486.
487.
#define putchar (c)
printf("%c",c)
void main()
{
char s='c';
putchar (s);
}
ans: error (gap should
not be there between putchar and
(c) )
488.
void main()
{
int a[]={9,4,1,7,5};
int *p;
p=&a[3];
printf("%d",p[-1]);
return(&i);
}
ans: 1
void main()
{
int a[]={10,20,30,40,50};
int *p;
p= (int*)((char *)a +
sizeof(int));
printf("%d",*p);
}
489.
502.
ans: 20
490.
OR
for(j=0;j<10;j++)
for(i=0;i<100;i++)
a[i][j]=0;
503.
main()
{
void print(int);
int i=5;
print(i);
}
void print(int n)
{
if(n>0)
{
print(n-1);
printf("%d",n);
print(n-1);
}
}
ans:
1213121412131215121312141
213121
501.
int * f(int a)
{
int i;
i=a;
void main ()
{
int
a[]={101,201,301,401,501,601,70
1,801,901,001};
int *p; clrscr ();
printf("%d ",a);
printf("arthi ");
printf("%d ", ((char *)a +
sizeof(int)));
p=(int *) ((char *) a +sizeof
(int));
printf("%d",*p);
}
void main ()
{
int
a[]={101,201,301,401,501,601,70
1,801,901,001};
int *p; clrscr ();
printf("%d ",a);
printf("arthi ");
printf("%d ", ((char *)-a +
sizeof(int)));
p=(int *) ((char *) a +sizeof
(int));
printf("%d",*p);
}
ans: error (illegal use of
pointer)
505.
main ()
{
int
a[10]={10,9,8,7,6,5,4,3,2,1};
clrscr();
int *p=a;
int *q=&a[7];
printf("%d %d ",q,p);
}
Char* foo(Str...)
{
char str[4];
strcpy(str,"HelloSoft");
return str;
}
ans: we can't return
address of auto variable
as it
is allocation is made in
stack which is
deallocated
when the function
returns.
main()
{
printf("%d",printf("HelloSoft"));
}
511.
ans: HelloSoft9
507.
main()
int a[10][20][30][40];
int *p
How to access an element of a
using p?
{
int i=3;
printf("%d %d %d",i++,i,+
+i);
ans: a[i][j][k][l]
512.
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.
ans: main()
{
int
i=10,k=5,j,a[10];
main()
{
int i=10;
if(i>20)
if(i==10)
printf("Hi");
else
printf("Bye");
}
ans: 4 4 4
508.
*(p+
ans: no output
513.
for(j=0;j<10;j++)
a[j]=65;
}
509.
main()
{
int *p=0x100;
int *q=0x100;
int k=p*q;
printf("%x\n",k);
}
b) for(j=0;j<1000;j++)
for(i=0;i<1000;i++)
temp=temp+a[i][j]
ans: a (just it is a guess.
In a we are accessing
elements which are in
adjacent locations. In b
we are accessing
elements which are
1000 locations apart)
514.
void main()
{
printf("%d",(float)3/2);
}
ans: 0
515.
void main()
{
char *s="Hello World";
printf("%c",s);
}
strcat(str,str);
ans: compilation error
(destination string
length should
accommodate both the
strings)
526.
int(*ptr)[10]
void main()
{
char *s="Hello World";
printf("%c",*s);
}
#define exp 5
main()
{
printf("%d",exp++);
}
fp,fs;
fp=fopen("tc.dat","w");
fs=fopen("tc.dat","w");
putch('A',fp);
putch('B',fs); What will happen?
10 integers.
527.
int main()
{
char *str = "Hello, world" ;
printf("%5s" , str);
}
ans: A is overwritten by
B
518.
519.
528.
520.
529.
521.
switch(float value)
int *ptr[10];
ans: declaration of 10
pointers
int main()
{
extern int i;
printf("%d" , i);
}
ans: linker error
main()
{
int a[5]={1,2,3,4,5};
int *p=a+1;
int *q=a+5;
int dif=q-p;
printf("%d", dif);
}
void temp();
void temp(void);
int main()
{
temp();
}
void temp()
{
printf("C is exciting!");
}
ans: 4
ans: C is exciting!
523.
switch(NULL)
531.
void temp();
void temp(void);
int main()
{
temp();
}
void temp(void)
{
printf("C is exciting!");
}
537.
main()
{
int x;
printf("\n
%d",x=0,x=20,x=40);
}
ans: 0
538.
main()
ans: C is exciting!
532.
void temp();
void temp(void);
int main()
{
temp(void);
}
void temp()
{
printf("C is exciting!");
}
{
int a[]={1,2,5,6,9,10};
int *b=&a[4];
printf("\n%d",b[-3]);
}
ans: 2
539.
main()
{
int x=0,y=1;
if(x=y)
y= 7;
else
y=2;
printf("%d", y);
}
void temp(int i)
{
if(i == 10) return;
i++ ;
temp(i);
printf("%d " , i);
}
int main()
{
temp(1);
}
ans: 10 9 8 7 6 5 4 3 2
534.
535.
int main()
{
char *str = "Hello, world";
int i = sizeof(str);
for( ; i >= 0 ; i--)
printf("%c" , str[i]);
}
int main()
{
int a = MAX( 4+2 , 3*2) ;
printf(" %d " , a);
}
ans: 7
540.
{
int i=39,count=0;
while( i & 1) //some
condition like this
{
count++;
i=i>>1;
}
printf("%d",count);
}
ans: 3
541.
main()
{
int i=39,count=0;
while( i & 1) //some
condition like this
{
count++;
i>>1;
}
printf("%d",count);
}
ans: infinite loop
542.
ans: 6
main()
main()
{
int x=128;
printf("\n%d",1+x++);
}
ans: 129
543.
ans: 99 99 99
548.
ans: a is pointer to an
array of 10 integers
main()
{
FILE *f1;
FILE *f2;
f1=fopen("myfile","w");
f2=fopen("myfile","w");
fputc('A',f1);
fputc('B',f2);
fclose(f1);
fclose(f2);
}
what does f1 n f2 conatins?
549.
Open a file "input" and print the
odd number of lines first on the screen and
then
even number of lines..something
like that.....
550.
main()
{
int x=5, y;
y= x*x++ * ++x ;
printf("%d %d",x,y);
}
ans: B
ans: 7 216
544.
if i/p is code friday monday
sunday in commad line then
main(int argc,char *argv[])
{
printf("\n%c",**++argv);
}
551.
main()
{
int a=10,b=5;
while(--b>=0 && ++a)
{
--b;
++a;
}
printf("%d %d",a,b);
}
ans:may be f
545.
#define max 10
main()
{
printf("\n%d",max++);
}
ans: 16 -2
552.
main()
{
char i;
for (i=0; i<=255; i++)
{
printf("%c", i);
}
}
main()
{
int
a[]={1,2,9,8,6,3,5,7,8,9};
int *p=a+1;
int *q=a+6;
printf("\n%d",q-p);
}
{
int i=0;
switch(i)
{
case 1: printf("hi");
case 0: printf("zero");
case 2: printf("world");
}
}
ans: 5
547.
main()
main()
{
int i=3;
while(i--){
int i=100;
i--;
printf("%d ",i);
}
}
ans: zeroworld
554.
struct XXX
{
int a:6;
float b:4;
char s;
}structure;
main()
main()
{
char *p='a';
int *i=100/ *p;
printf("%d",i);
}
{
printf("%d",sizeof(structure));
}
ans: error (bit fields
must be signed or unsigned int)
555.
struct XXX
{
int a:6;
/*float b:4;*/
char s;
}structure;
main()
{
560.
printf("%d",sizeof(structure));
}
561.
How long the following program
will run?
main()
{
printf("\nSonata Software");
main();
}
ans: 2
556.
struct XXX
{
int a:6;
/*char s;*/
}structure;
main()
{
main()
{
int n=5;
printf("\nn=%*d",n,n);
}
ans: n=
5 (width
specifier %5d right justified)
main()
{
const int x=5;
int *ptrx;
ptrx=&x;
*ptrx=10;
/*x=10;*/
printf("%d",x);
}
printf("%d",sizeof(structure));
}
ans: 1
557.
struct XXX
{
int a;
char s;
}structure;
main()
{
main()
{
const int x=5;
int *ptrx;
ptrx=&x;
*ptrx=10;
x=15;
printf("%d",x);
}
printf("%d",sizeof(structure));
}
ans: 3
558.
main()
{
char *s;
s="hot java";
strcpy(s,"solaris java");
printf("%s",s);
}
main()
{
const char *fun();
*fun()="A";
}
const char *fun()
{
return "Hello";
}
main()
{
int a=10;
void f();
a=f();
printf("\n%d",a);
}
void f()
{
printf("\nHi");
}
567.
In the following program how would
you print 50 using p?
main()
{
int a[]={10, 20, 30, 40,
50};
char *p;
p= (char*) a;
}
568.
Point out the error in the following
program
572.
ans:
printf("%d",*((int*)p+4)); or
printf("%d",*(p+8));
main()
{
char near * near *ptr1;
char near * far *ptr2;
char near * huge *ptr3;
printf("%d %d
%d",sizeof(ptr1),sizeof(ptr2),sizeof(ptr3));
ans: 2 4 4
573.
What is the difference between the
following declarations?
const char *const s; char const
*const s;
ans. No difference
574.
What is the difference between the
following declarations?
const char *s;
char const *s;
ans. No difference
575.
main()
{
int y=128;
const int x; x=y;
printf("%d",x);
}
581.
main()
{
int y=128;
const int x=y;
printf("%d",x);
}
577.
582.
main()
ans: C:\MYPROG.EXE 1 2
main()
{
const int x;
x=128;
printf("%d",x);
}
{
FILE *fp;
fp= fopen("trial","r");
}
fp points to:
578.
In the following code, is p2 an
integer or an integer pointer?
typedef int* ptr
ptr p1,p2;
583.
What is the type of the variable b
in the following declaration?
#define FLOATPTR float*
FLOATPTR a,b;
ans: float
584.
{
FLOATPTR a,b;
b=10.0;
}
588.
In the following code, in which
order the functions would be called?
a= f1(23,14)*f2(12/4)+f3();
ans: f1, f2, f3
589.
{
printf("three ");
return 1;
}
f1(int x, int y)
{
printf("one ");
return(x+y);
}
f2(int x)
{
printf("two ");
return x;
}
f3()
main()
{
int a;
a= f1(23,14)*f2(12/4)+f3();
printf("%d",a);
}
ans: one two three 112
ans: 11
590.
587.
main()
main()
{
int i=4;
switch(i)
{
default:
printf("\n A mouse is an
elephant built by the Japanese");
case 1:
printf(" Breeding rabbits is
a hair raising experience");
break;
case 2:
printf("\n Friction is a
drag");
break;
case 3:
printf("\n If practice make
perfect, then nobody's perfect");
}
}
{
int a=10,b;
a<= 5 ? b=100 : b=200;
printf("\n%d",b);
}
ans: error (lvalue
required. Conditional
operator has highest
priority than
assignment operator)
591.
{
int a=10,b;
a<= 5 ? b=100 : (b=200);
printf("\n%d",b);
}
ans: 200
592.
ans: A mouse is an
elephant built by the
Japanese Breeding
rabbits is a hair raising
experience
main()
main()
{
int a=10,b;
a>= 5 ? b=100 : (b=200);
printf("\n%d",b);
}
ans: 100
593.
printf("%d",B);
}
main()
{
int i=1;
switch(i)
{
case 1:
printf("\nRadioactive cats
have 18 half-lives");
break;
case 1*2+4:
printf("\nBottle for rent
-inquire within");
break;
}
}
ans: -1
599.
{
unsigned int B=0xFFFF;
~B ;
printf("%u",B);
}
ans: 65535
600.
Func(int a, intb)
{
int a;
a=10;
return a;
}
will there be any error?
main()
{
int i=2;
printf("I=%d i=%d",++i,+
+i);
}
ans: I=4 i=3
595.
main()
main()
{
unsigned char i=0x80;
printf("i=%d",i<<1);
}
main()
{
unsigned char i=0x80;
i=i<<1;
printf("i=%d",i);
}
ans: i=0
597.
main()
{
int B=0xFFFF;
~B ;
note: not assigned to B */
printf("%d",B);
}
/*
603.
ans: -1
598.
main()
ans: 11
{
unsigned int B=0xFFFF;
~B ;
604.
main()
{
char c='a';
printf("%d %d",
sizeof(c),sizeof('a'));
}
printf("%d\n",(*fn1)());
}
int fn(void)
{
return(i-=5);
}
ans: 1 2
605.
main()
{
char c='a';
Printf("%d %d",
sizeof(c),sizeof('a'));
}
ans: linker error
(undefined symbol_Printf)
606.
ans: 5
609.
void main(void)
{
char numbers[5]
[6]={"Zero","One","Two","Three","Four"};
printf("%s is
%c",&numbers[4][0],numbers[0][0]);
}
main()
{
Char c='a';
printf("%d %d",
sizeof(c),sizeof('a'));
}
ans: Four is Z
610.
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);
}
ans: error (incompatible
type conversion)
608.
int fn(void);
void print(int,int(*)());
int i=10;
ans: 4.50
4.57
13.57
612.
void main(void)
{
int i=20;
print(i,fn);
}
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);
}
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;
}
printf("%d ",i);
i--;
}
}
int print(int x)
{
static int i=2;
return(i--);
}
void main(void)
{
int i=100,j=20;
i++ =j;
i*=j;
printf("%d\t%d\n",i,j);
}
ans: 100 99
617.
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++);
}
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);
}
ans: (100,C, 100)
618.
main()
{
char *p1="Name";
char *p2;
p2=(char *)malloc(20);
while(*p2++=*p1++);
printf("%s\n",p2);
}
ans: Sum= 39
615.
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);
}
main()
ans: 6 (maximum of
three numbers)
{
int x=20,y=35;
x = y++ + x++;
y = ++y + ++x;
printf("%d %d\n",x,y);
}
616.
ans: 57 94
620.
main()
{
int x=5;
printf("%d %d
%d\n",x,x<<2,x>>2);
temp=a;
b=a;
a=temp;
return;
}
ans: 5 20 1
621.
#define swap1(a,b) a=a+b;b=ab;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;
}
main()
{
char *ptr = "Ramco
Systems";
(*ptr)++;
printf("%s\n",ptr);
ptr++;
printf("%s\n",ptr);
}
ans: Samco Systems
amco Systems
625.
main()
ans: 10 5
10 5
622.
#define swap1(a,b) a=a+b;b=ab;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;
}
{
char s1[]="Ramco";
char s2[]="Systems";
s1=s2;
printf("%s",s1);
}
ans: error (lvalue
required)
626.
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: 10 5
10 5
ans: RamcoSystems
627.
623.
#define swap1(a,b) a=a+b;b=ab;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;
main()
{
int x=10,y=15;
x=x++;
y=++y;
printf("%d %d\n",x,y);
}
ans: 11 16
628.
main()
{
int a=0;
if(a=0) printf("Ramco
Systems\n");
printf("%d",((a+9) +
(a+1)));
printf("Ramco Systems\n");
}
ans: Ramco Systems
629.
main()
Systems\n");
printf("Ramco Systems\n");
}
ans: Ramco Systems
Ramco Systems
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;
}
ans: 45
631.
{
int a=0;
if(a==0) printf("Ramco
630.
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);
}
ans: 5 20 5
634.
%.2f";
sum=i+j+k;
ave=sum/3.0;
printf(myformat,ave);
}
ans: ave=43.33
632.
void main(void)
{
int a[10];
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 ",*(a++)+i);
}
ans: 5 5 5 5 5
636.
*(a+k)=k;
sum+=a[--k];
printf("%d",sum);
}
}
ans: There is nothing on
the screen and prog
waits till the memory
lasts and then out of
memory run time error.
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);
}
ans: 99
638.
main()
{
printf("Hello
%d",printf("QUARK test? "));
}
ans: QUARK test? Hello
12
639.
main()
{
int i,j,A;
for (A = -1;A<=1; A++)
printf("%d ",!!A);
}
643.
ans: 12
644.
main()
ans: uark
645.
}
ans: 1 24
646.
void main()
{
int x=3;
printf("%d %d",x>>1,
x<<3);
{
int i=255;
printf("%d\t",++(i++));
}
641.
main()
{
void fun1(void *);
char a[] = "quark";
void *temp;
temp = a;
fun1(temp);}
void fun1(void *temp1 )
{
int t1 = 0;
while(*((char*)temp1+ t1+
+ )!='\0') {
printf("%c",*((char*)temp1
+ t1));
}
}
ans: 1 0 1
640.
void main()
{
int *x;
x =(int *) 15;
}
main()
{
int i,j;
printf("QUARK
%s\n",main());
ans. static
648.
int *func()
{
static int x=0;
x++; return &x;
}
int main()
{
int * y = func();
printf("%d ",(*y)++);
func();
printf("%d",*y);
return 0;
}
ans: 1 3
649.
void main()
{
unsigned int x= -1;
int y =0;
if(y<=x) printf("A is
true\n");
if (y ==(x = -10)) printf("B
is true\n");
if ((int) x>=y) printf("C is
true\n");
}
void main()
{
unsigned int x= -1;
int y =0;
printf("%u ",x);
if(y<=x) printf("A is
true\n");
if (y ==(x = -10)) printf("B
is true\n");
if ((int) x>=y) printf("C is
true\n");
}
ans: 65535 A is true (%u
unsigned integer specifier)
653.
In the following code what is the
correct way to increment the variable ptr
to
point to the next member of the
array
union intfloat
{
int intArray[ 5];
float floatArray[ 5];
};
union intfloat arr[20];
void *ptr =arr;
ans: A is true
650.
void main()
{
int x= -1;
int y =0;
if(y<=x) printf("A is
true\n");
if (y ==(x = -10)) printf("B
is true\n");
if ((int) x>=y) printf("C is
true\n");
}
ans: no output
void main()
{
unsigned int x= -1;
int y =0;
printf("%d ",x);
if(y<=x) printf("A is
true\n");
if (y ==(x = -10)) printf("B
is true\n");
if ((int) x>=y) printf("C is
true\n");
}
651.
main()
{
z=2
z=2
z=3
printf("%d %d",
sizeof(NULL), sizeof(""));
}
658.
ans: 4 1 (NULL is a
pointer so it takes 4
bytes. sizeof empty
string is 1)
656.
int *check(int,int);
void main()
{
int c,d;
c = check(11,29);
d= check(20,30);
printf("\nc=%u",c);
}
int * check(int i,int j )
{
int *p, *q;
p=&i;
q=&j;
if(i>=95)
return(q);
else
return(p);
}
void main()
{
int a[3][2]={ 1,8,5,7,6,8};
printf("%d ",a);
printf("%d ",&a);
printf("%d ",*a);
}
ans: 8682 8682 8682 (all
are same)
659.
main()
{
char str1[]="Hello";
char str2[]="Hello";
if(str1==str2 &&
(*(str1+6)== *(str2+6)) )
printf("\n Equal");
else
printf("\n unequal");
}
ans: unequal
660.
main()
{
int a, b=255,c=127;
a=~b;
c=c^(~a & b|0);
c=c^(~(~b));
printf("%d\n",c);
}
ans: nonportable
pointer conversion
657.
void main()
{
int a[3][2]={ 1,8,5,7,6,8};
printf("%d",((a+1)(&a+1)));
}
ans: 2. I havent been
able to figure this one
out. a is the address of
the 2-d array, here a,
&a, *a all give the same
value, i.e., address of
the array. (a+1) gives
the address of the
second row, it is the
same as a[1]. *(a+1)
gives the address of the
first cell of the second
row. **(a+1) gives the
value of the element
stored in the first cell in
the second row.
(*(a+1)+1) gives the
address of the second
cell of the second row.
*(*(a+1)+1) gives the
value of the element
stored in the second cell
in the second row.
ans: 127
661.
662.
main()
{
int i,j=9999;
char buff[5];
i=sprintf(buff,"%d",j);
printf("%d %s",i,buff);
}
ans: 4 9999
663.
main()
{
int i,j=99999;
char buff[5];
i=sprintf(buff,"%d",j);
printf("%d %s",i,buff);
}
{
int i=0,z;
z=sizeof(++i + i++);
printf("%d %d",z,i);
}
ans: 6 -31073
664.
main()
{
int I=2;
int j=3;
int k=4;
printf("%d",(I<j<k));
}
670.
main()
ans: 1
665.
#define macro(a) ((a++) + (++a)
+ (a++))
main()
{
printf("%d",macro(1));
}
{
int y=10;
for (int x=0;x<=10;x++);
y+=x;
printf("%d",y);
}
ans: error (x should be
declared before for loop)
671.
int func(int I)
{
static int k=0;
k++;
if(k>5)
return 1;
else
return func(I-1);
}
{
int y=10,x;
for (x=0;x<=10;x++);
y+=x;
printf("%d",y);
}
ans: 21
672.
int main()
{
printf("%d",func(1));
}
ans: 1
667.
ans: quarkmedia
main()
{
char *str;
str="hello" "india";
printf("%s",str);
}
ans: helloindia
669.
fun(int a)
{
static int b;
}
what is the storage allocation for
both a and b?
ans: a-stack, b-bss
(block starting with symbol)
main()
{
char *str="quark" "media";
printf("%s",str);
}
668.
main()
main()
673.
int *fun(int a)
{
return (&a);
}
int *fun(int a)
{
int *b;
b=&a;
return(b);
}
int *fun(int a )
{
int *b;
b=malloc(sizeof(int));
b=&a;
return (b);
}
679.
main()
{
int i;
printf("%d",++i++);
}
ans: error (lvalue
required)
676.
main()
{
int a=2;
printf("%d %d %d",++a,a+
+);
jill
}
681.
ans: 4 2 garbage value
677.
struct abc
{
char a[10];
int a,b;
};
main()
{
struct abc ab={"main"};
printf("%d %d",ab.a,ab.c);
}
ans: error (multiple
declaration of a and undefined
symbol c)
678.
void main()
{
printf("persistent");
main();
}
ans: till stack overflows
void main()
{
int a[5] ={1,2,3,4,5},i,j=2;
for (i =0;i<5;i++ )
func(j,&a[i]);
for (i =0;i<5;i++ )
printf("%d ",a[i]);
}
func(int j,int *a)
{
j=j+1;
a=a+j;
}
ans: 1 2 3 4 5
682.
void main()
{
int a[5] ={1,2,3,4,5},i,j=2;
for (i =0;i<5;i++ )
func(j,a[i]);
for (i =0;i<5;i++ )
printf("%d ",a[i]);
}
func(int j,int *a)
{
j=j+1;
a=a+j;
}
int k=0,i=0,j=1;
if(!0&&(k=2)) printf("%d
",k);
if(!0||(k=0))
printf("%d",k);
}
ans: 1 2 3 4 5
683.
main()
ans: 2 2
{
for (a=1;a<=100;a++)
for(b=a;b<=100;b++)
foo();
}
foo()
{}
how many times foo will be
688.
main()
{
int k=0,i=0,j=1;
if(!0&&k=2) printf("%d
",k);
if(!0||k=0)
printf("%d",k);
}
called?
ans: 5050
684.
int i;
main()
main()
{
int a,b;
for (a=1;a<=100;a++)
for(b=a;b<=100;b++)
foo();
printf("%d",i);
}
{
int i;
for(i=0;i<3;i++)
switch(i)
{
case 1: printf("%d",i);
case 2 : printf("%d",i);
default: printf("%d",i);
}
}
foo()
{
i++;
}
ans: 011122
ans: 5050
690.
685.
One palindrome programme was
given in recursion
ans : pal(f++,t--)
686.
main()
{
int i=foo(2);
printf("%d",i);
}
foo(int s)
{
if(!s)
return s;
else
{
int i=5;
return i;
}
}
ans: 5
687.
int *num={10,1,5,22,90};
main()
{
int *p,*q;
int i;
p=num;
q=num+2;
i=*p++;
printf("%d %d",i,q-p);
}
ans: error (declaration
error)
691.
int num[]={10,1,5,22,90};
main()
{
int *p,*q;
int i;
p=num;
q=num+2;
i=*p++;
printf("%d %d",i,q-p);
}
main()
{
ans: 10 1
692.
printf("%u",-1);
}
ans: 65535
698.
main()
{
char
*a[4]={"jaya","mahe","chandra","b
uchi"};
printf("%d %d
%d",sizeof(a),sizeof(char
*),sizeof(a)/sizeof(char *));
}
ans: 16 4 4
694.
700.
main()
{
int x=2;
x<<2;
printf("%d ",x);
}
ans: 2,3
695.
ans: 2
701.
main()
{
int x=2;
x=x<<2;
printf("%d ",x);
}
ans: %s is a string is a
string
696.
main()
{
char *p="abc";
char *q="abc123";
while(*p=*q)
printf("%c%c",*p,*q);
}
ans: prints a infinite
times
697.
main()
ans: 8
702.
main()
{
int a[]={0,0X4,4,9};
int i=2;
printf("%d %d",a[i],i[a]);
}
ans: 4 4
703.
main()
temp=x;
x=y;
y=temp;
}
{
int i=2+3,4>3,2;
printf("%d",i);
}
main()
ans: error
704.
{
int x=2,y=3;
swap(x,y);
printf(%d %d,x,y);
}
main()
{
int i=(2+3,4>3,2);
printf("%d",i);
}
ans: 2
705.
ans: 2 3
709.
main()
{
int a=0,b=0;
if(!a)
{
b=!a;
if(b)
a=!b;
}
printf("%d %d",a,b);
}
struct
{
int x;
int y;
}abc;
x cannot be accessed by
the following
1)abc-->x;
2)abc[0]-->x;
3)abc.x;
4)(abc)-->x;
ans: 0 1
706.
main()
{
int I=10;
I=I++ + ++I;
printf("%d",I);
}
ans: 23
707.
swap(int x,y)
{
int temp;
temp=x;
x=y;
y=temp;
}
ans: 1 2 &4
710.
Automatic variables are destroyed
after fn. ends because
a) Stored in swap
b) Stored in stack and poped out
after fn. returns
c) Stored in data area
d) Stored in disk
ans: b
711.
main()
{
int x=2,y=6,z=6;
x=y==z;
printf("%d",x);
}
main()
{
int x=2,y=3;
swap(x,y);
printf(%d %d,x,y);
}
ans: error (swap
function formal arguments
declaration)
708.
swap(int x, int y)
{
int temp;
ans: 1
712.
i ) int *F()
ii) int (*F)()
ans: The first declaraion
is a function returning a
pointer to an integer
and the second is a
pointer to a function
returning int.
713.
#define dprintf(expr) printf(#expr
"=%d\n",expr)
main()
{
int x=7;
int y=3;
dprintf(x/y);
}
ans: 3 4
719.
int x= 0x65;
main()
{
char x;
printf("%d\n",x);
}
ans: x/y=2
ans: unknown
714.
main()
{
int i;
char *p;
i=0X89;
p=(char *)i;
p++;
printf("%x %x\n",i,p);
}
720.
main()
{
int a=10;
int b=6;
if(a=3)
b++;
printf("%d %d\n",a,b++);
}
ans: 89 8a
715.
main()
ans: 3 7
721.
{
int i;
char *p;
i=0X89;
p=(char *)i;
p++;
printf("%x %x\n",p,i);
}
{
enum Months {JAN
=1,FEB,MAR,APR};
Months X = JAN;
if(X==1)
{
printf("Jan is the first
month");
}
}
ans: 8a 0
716.
The type of the controlling
expression of a switch
statement cannot be of the type
ans: error
722.
none
ans: d)float
main()
{
int X,b;
b=7;
X = b>8 ? b <<3 : b>4 ?
b>>1:b;
printf("%d",X);
}
ans: 3
718.
main()
{
int n=2;
printf("%d %d\n", ++n,
n*n);
}
main()
{
enum Months {JAN
=1,FEB,MAR,APR};
enum Months X = JAN;
if(X==1)
{
printf("Jan is the first
month");
}
}
717.
main()
main()
{
int l=6;
switch(l)
{
default : l+=2;
case 4: l=4;
case 5: l++;
break;
}
printf("%d",l);
}
ans: 2 and 0
729.
main()
{
int i=20,*j=&i;
f1(j);
*j+=10;
f2(j);
printf("%d and %d",i,*j);
}
ans: 5
724.
main()
{
int x=20;
int y=10;
swap(x,y);
printf("%d %d",y,x+2);
}
swap(int x,int y)
{
int temp;
temp =x;
x=y;
y=temp;
}
ans: 10 22
725.
f1(k)
int *k;
{ *k+=15;}
f2(x)
int *x;
{ int m=*x, *n=&m;
*n+=10;
}
ans: 45 and 45
730.
func(int x)
{
if(x<=0)
return (1);
return func(x-1)+x;
}
main()
{
printf("%d",func(5));
}
ans: 16
726.
main()
{
char s[]="Hello, world";
printf("%15.10s",s);
}
ans:
727.
731.
Hello, wor
main()
{
printf("%d\n",f(7));
}
f(x)
{
if(x<=4)
return x;
return f(--x);
}
ans: 4
ans: 55 55
728.
main()
{
int x=0 ,*p=0;
x++;p++;
printf("%d and %d\n",p);
}
732.
main()
{
int x=0,*p=0;
x++; p++;
printf ("%d and %d\n",x,p);
}
738.
main()
ans: 1 and 2
733.
{
int a=10,b=33;
a=a^b;
b=a^b;
a=a^b;
printf("%d %d", a,b);
}
main()
{
int Y=10;
if( Y++>9 && Y++!=10 &&
Y++>10)
printf("%d",Y);
else
printf("........");
}
ans: 33 10
739.
{
int *a;
int (*b)();
printf("%d
%d",sizeof(a),sizeof(b));
}
ans: 13
734.
int i=10;
main()
{
int i=20,n;
for(n=0;n<=i;n++)
{
int i=10;
i++;
}
printf("%d", i);
}
main()
ans: 4 4
740.
main()
{
int i;
char *p;
i=0X89;
p=(char *)i;
p++;
printf("%x\n",p);
}
ans: 20
735.
main()
{
int i=20,j,k=0;
for(j=1;j<i;j=1+4*(i/j))
{
k+=j<10?4:3;
}
printf("%d", k);
}
ans: 8a
741.
{
int x=0,*p=0;
x++; p++;
printf ("%d and %d\n",x,p);
}
ans: 4
736.
main()
ans: 1 and 2
742.
{
int i=10;
printf("%d %d %d",i++,i+
+,i--);
}
ans: 10 9 10
737.
main()
%d",i);
743.
{
int i=10;
if(1,i++,++i)
printf("The value for i is
main()
}
ans: The value for i is 12
744.
main()
{
int a ,b=7;
a=b<4?b<<1:b=4?71:a;
printf("%d",a);
}
ans: error (lvalue
required)
745.
main()
{
int a ,b=7;
a=b<4?b<<1:(b=4?
ans: 5 and 7
750.
which of the following is not basic
data type
ans: char * (pointers
derived data types)
751.
the declaration of the variable does
not result in one of
the following
ans: allocation of the
storage space for the varable.
71:a);
printf("%d",a);
}
752.
2 variables cannot have the same
name if they are
ans: 71
ans: in the same block.
746.
main()
{
int a,b;
a=(10.15);
b=10,15;
printf("%d %d",a,b);
}
753.
Which of the following is the
correct code for strcpy, that
is used to copy the contents from
src to dest?
a) strcpy (char *dst,char *src)
{
while (*src)
*dst++ = *src++;
}
b) strcpy (char *dst,char *src)
{
while(*dst++ = *src++);
}
c) strcpy (char *dst,char *src)
{
while(*src)
{ *dst = *src;
dst++; src++;
}
}
d) strcpy(char *dst, char *src)
{
while(*++dst = *++src);
}
ans: 10 10 (a value is
truncated, no effect of
comma operator, it is
just assignment)
747.
main()
{
int a,b;
a=(10.15);
b=(10,15);
printf("%d %d",a,b);
}
ans: 10 15 (a value is
truncated and effect of
comma operator)
748.
main()
{
int a,b;
a=(10,15);
b=10,15;
printf("%d %d",a,b);
}
ans: 15 10
749.
main()
{
int X,b=7;
X = b>8 ? b <<3 : b>4 ?
b>>1:b;
printf("%d",X);
}
ans: 3
755.
main()
{
char *src = "Hello World";
char *dst;
dst = (char *)malloc(20);
while(*dst = *src){dst+
+;src++;}
printf("%s",dst);
getch();
}
760.
int main()
{
int *ptr;
FUNC(ptr);
printf("Ptr:%x",ptr);
return 0;
}
ans: no output
756.
main()
{
char *src = "Hello World";
char *dst;
dst = (char *)malloc(20);
while(*dst++ = *src++);
printf("%s",dst);
getch();
}
int main()
{
char a[] = "world";
printf("%d
%d\n",strlen(a),sizeof(a));
return 0;
}
ans: 5 6
757.
main()
{
char *src = "Hello World";
char *dst;
while(*dst++ = *src++);
printf("%s",dst);
getch();
}
ans: error (use of dst
before definition. Assign some
address to dst)
758.
762.
{
char *s = "Hello";
printf("%s",1(s));
}
ans: error (call of
nonfunction)
763.
main()
{
char *s = "Hello";
printf("%s",1[s]);
}
main()
{
char *src = "Hello World";
char dst[20];
while(*dst++ = *src++);
printf("%s",dst);
getch();
}
int main()
{
for(;;);
printf("Hello\n");
return 0;
}
main()
{
char *s = "Hello";
printf("%s",&1[s]);
}
main()
ans: ello
765.
char ( * ( f () ) [] )()
ans: f is a function
returning pointer to
array[] of pointer to
function returning char.
766.
char c;
scanf("%s",c);
}
ans: it asks for a
character when you
type a character it will
give error because 99
memory location i.e., c
(which is protected
memory and not
accessible) is used to
store typed character.
main()
{
int i;
i=(2,3);
printf("%d",i);
}
ans: 3
767.
main()
772.
{
char str[]="GESL";
printf("%d
%d",sizeof(str),strlen(str));
}
main()
{
int k=5;
for(++k<5 && k++/5 || +
+k<8);
printf("%d\n",k);
}
ans: 5 4
768.
main()
{
int i;
for(i=0;i++;i<100)
printf("hello world\n");
}
773.
main()
{
int k=5;
if(++k<5 && k++/5 || +
+k<8);
769.
printf("%d\n",k);
}
main()
ans: 7
{
char i;
for(i=1;i++;i<100)
printf("hello world %d\n",i);
}
774.
main()
{
int k=5;
if(++k<5 && k++/5 && +
+k<8);
printf("%d\n",k);
}
ans: 6
775.
770.
{
int k=5;
if(++k<5 || k++/5 && +
{
int i;
for(i=1;i++;i<100)
printf("hello world %d\n",i);
}
ans: hello world
1.hello world
32767hello world
-32768....hello world
-1..hello world 0
771.
main()
main()
main()
+k<8);
printf("%d\n",k);
}
ans: 8
776.
main()
{
int k=5;
if(++k<5 || k++/5 || +
+k<8);
printf("%d\n",k);
ptr2=func(20,10,ptr1);
printf("%d
%d\n",*ptr1,*ptr2);
}
ans: 7
777.
ans: 10 30
780.
ans: True
781.
int main()
{
int i=10,j;
if((j=~i)<i)
printf ( "True" ) ;
else
printf ( "False" ) ;
}
int main()
{
int i=10,j;
if((j=~i)<i)
printf ( "True" ) ;
else
printf ( "False" ) ;
}
ans: Flase
782.
int main()
{
unsigned int i=-10,j=10;
if(j<i)
printf ( "True " ) ;
else
printf ( "False " ) ;
printf("%d %u",i,i);
}
ans: True -10 65526
783.
main()
{
FILE *fp;
printf("%d\n",sizeof(fp));
}
ans: 4 (pointer takes 4
bytes)
779.
784.
main()
{
int a=10,b=20;
a^=b^=a^=b;
printf("%d %d\n",a,b);
}
ans: 20 10
785.
main()
{
int a=10,20;
int b;
a^=b^=a^=b;
printf("%d %d\n",a,b);
}
char ch ;
double db ;
};
main()
{
printf("%d\n",sizeof(struct
SIZE));
error)
786.
main()
{
int a,b;
a=(10,15);
b=10,15;
printf("%d %d",a,b);
}
ans: 12 (actually it
takes 11 bytes since
packing is there it takes
12 bytes)
791.
{
int arr[]={ 1,2,3,4 };
int *ptr ;;;;
ptr++ = arr;
printf("%d,
%d",ptr[2],arr[2]);
return 0;
}
ans: 15 10
787.
main()
{
int i=10;
switch(i)
{
case 10: printf("Hello ");
{
case 1 : printf("World ");
}
case 5: printf("Hello World
main()
main()
{
char s[10];
scanf ("%s",s);
printf(s);
}
what is the output if input
");
}
}
ans: Hello World Hello
World
788.
is abcd
main()
ans: abcd
{
char str1[]="Hello";
char str2[]="Hello";
if ( str1==str2 )
printf("True\n");
else
printf("False\n");
}
793.
main()
{
char c = 255;
printf ("%d",c);
return 0;
}
ans: -1
ans: False
794.
789.
main()
main()
{
int i;
for (i=7;i<=0;i--)
printf ("hello\n");
}
{
# include <stdio.h>
int i = 10 ;
printf("%d\n", i/2 );
}
ans: 5
790.
#pragma pack(2)
struct SIZE
{
int i;
795.
main()
{
printf( printf ("world") );
}
main()
{
scanf("%d");
printf();
}
ans: c)
802.
For a linked list implementation
which searching technique is not
applicable?
a)linear search
b)none
c)quick sort
d)binary search
ans: d)
803.
797.
main()
{
scanf("%d");
printf("manu");
}
ans: manu (whatever
you type for scanf output will
be manu)
ans: a)
804.
798.
#define islower(c) ('a'<=(c) &&
(c)<='z')
#define toupper(c) (islower(c)?(c)('a'-'A'):(c))
main()
{
char *p="i am fine";
while(*p)
printf("%c",toupper(*p+
+));
}
805.
main()
{
200;
printf("tricky problem");
}
ans: c)
806.
what is Little-endian.
a) MSB at lower address LSB at
higher address
b) LSB at lower address MSB at
higher address
c) memory mgmt technique
d) none of the above
ans: b)
what is big-endian.
a) MSB at lower address LSB at
higher address
b) LSB at lower address MSB at
higher address
c) memory mgmt technique
d) none of the above
ans: 20 4 (mess is an
array of 5 pointers and
mess[1] is pointer. Here
pointer takes 4 bytes)
ans: a)
801.
what is the correct prototype of
printf function ?
a)printf(char *p,...);
b)printf(const *char *p,...);
c)printf(const char *p,...);
void main()
{
char
*mess[]={"Have","a","nice","day","
Bye"};
printf("%d
%d",sizeof(mess),sizeof(mess[1]));
}
807.
void main()
{
int i,count=0;
char *p1="abcdefghij";
char *p2="alcmenfoip";
for(i=0;i<=strlen(p1);i++)
{
if(*p1++ == *p2++)
count+=5;
else
count-=3;
}
printf("count=
%d\n",count);
}
printf("False\n");
}
ans: True
813.
int (*fun())[]
main()
{
int a=8,d;
int *p;
p=&a;
d=a/*p;
printf("%d\n",d);
}
ans: count=6
808.
what does main return on
successful execution?
a. 1
b. 0
c. -1
d.Nonzero
ans: b
815.
809.
main()
{
int a=8,d;
int *p;
p=&a;
d=a/ *p;
printf("%d\n",d);
}
ans: 1
816.
main()
{
char *a="Hello";
a++ = 'h';
printf("%s\n",a);
}
ans: c
811.
main()
{
int a;
char *p;
a = sizeof(int) * p;
printf("%d\n",a);
}
817.
{
char *a="Hello";
*a++ = 'h';
printf("%s\n",a);
}
main()
main()
{
char p[]="Hello";
p[0]='h';
printf("%s\n", p);
ans: hello
825.
819.
{
int i;
for(i=0; i< 10; i++)
{
int j=10;
j++;
printf("j= %d\n", j);
}
}
ans: j= 11 will be
printed 10 times
main()
{
int *p=10;
printf("%d\n",*p);
}
826.
main()
{
int *p=10;
printf("%d\n",p);
}
827.
main()
{
int i=-1;
i<<=2;
printf("%d\n",i);
}
ans: -4
823.
main()
{
int i= 0xffffffff;
printf("%d\n",i);
}
union test
{
int a;
union test *p;
};
main()
{
union test q;
printf(" a= %d\n ", q.a);
}
ans: a= garbage value
ans: 10
822.
main()
828.
#define dprint(expr) printf(" expr=
%d \n ", expr)
main()
{
int i=10,j=2;
dprint(i/j);
}
ans: expr= 5
ans: -1
829.
824.
main()
{
int A=1,B=2;
if(A==B < printf("Hello "))
printf("world\n");
else
printf("Bangalore\n");
}
main()
{
int *p ;
p=(int *)malloc(-10);
printf("%d",p);
free(p);
}
ans: 0 (no space is
allocated for p. p is a null
pointer)
830.
{
int i=100 ;
printf("%d ", sizeof(++i);
printf("%d ",i) ;
}
main()
{
int *p ;
p=(int *)malloc(10);
printf("%d",p);
free(p);
}
ans: 2266 (starting
address of the allocated block)
831.
{
int i=100 ;
printf("%d ", sizeof(++i+
main()
{
for(printf("a");printf("b");pri
ntf("c"));
}
+));
printf("%d ",i) ;
}
ans: abcbcbcbcbcb.
Infinite loop
832.
main()
fun()
{
return 10 ;
}
****837.
Which one of the following
data structures is best suited for
searching ?
main()
{
int i= 10 * fun() ;
printf("%d",i);
}
a) Arrays
b) Singly Linked List
c) Doubly Linked List
d) Hash Table
ans: 100
833.
fun()
{
return 10 ;
}
int i= 10 * fun() ;
main()
{
printf("%d",i) ;
}
ans: d)
****838.
Which of the following data
structures is best suited for
Deletion ?
a) Arrays
b) Singly Linked List
c) Doubly Linked List
d) Hash Table
ans: c)
839.
main()
{
int i=100 ;
printf("%d ", sizeof(i++));
printf("%d ",i) ;
}
ans: a)
ans: 2 100 (sizeof
operator operand will not be
evaluated)
835.
main()
840.
c) Deadlock Prevention
d) All of the above
{
int i=1 ;
printf(i ?"one" : "zero") ;
}
ans: b)
841.
main()
ans: one
{
int a = 1;
#define p a
printf("%d %d ",a++,p++);
}
848.
main()
{
int i=1;
printf("%d",i ? 1 : 0) ;
}
ans: 2 1
ans: 1
842.
main()
{
#include<stdio.h>
int a = 90 ;
printf("%d",a) ;
}
849.
main()
{
int a=90,b=100;
a++;
a=(a ^ b) ^ (a = b );
b = a^b^a ;
--a ;
printf("%d %d",a++,b++) ;
}
ans: 90
843.
main()
{
main() ;
}
ans: 90 100
850.
{
int a = 10 , b = 100 ;
swap(&a , &b) ;
printf("%d %d",a,b) ;
}
swap(int *a , int *b)
{
*a = *a + *b ;
*b = *a - *b ;
*a = *a - *b ;
swap1(&a , &b) ;
}
swap1(int **a , int **b)
{
**a = **a + **b ;
**b = **a - **b ;
**a = **a - **b ;
}
845.
main()
846.
typedef int *p ;
main()
{
int a = 90 ;
p p1 ;
p1 = &a ;
printf("%d",*p1) ;
}
ans: 90
847.
main()
ans: 10 100
851.
main()
{
void *ptr ;
int a = 10 ;
ptr = &a ;
printf("%d",*ptr) ;
}
ans: error (indirection
operator * should not be
applied on void pointer.
Since compiler does not
int a = 1 ;
int b = 0 ;
a = a++ + --b * a++ ;
printf("%d",a) ;
}
main()
{
void *ptr ;
int a = 90 ;
char *ptr1 = "hello" ;
ptr = a ;
ptr = ptr1 ;
}
ans: 2
858.
struct s
{
int si;
union u
{
float uf;
char uc;
};
};
main()
{
char *p = "helloo" ;
char *p1 = "strcat" ;
while((*(p++) = *(p1++)) !
main()
{
printf("%d",sizeof(struct
s));
= '\0')
}
{
;
}
}
ans: declaration
terminated incorrectly
859.
struct s
{
int si;
union u
{
float uf;
char uc;
}a;
};
int g = 10 ;
main()
{
int g = 10 ;
printf("%d",g) ;
}
int g ;
main()
{
printf("%d",sizeof(struct
ans: 10
s));
855.
int g = 10 ;
main()
{
extern int g;
printf("%d",g) ;
}
int g ;
}
ans: 6
860.
ans: 10
856.
//int g = 10 ;
main()
{
extern int g;
printf("%d",g) ;
}
int g ;
struct st
{
int a;
char b;
}
main()
{
}
ans: struct st is return
type of main (since
statement termination
is not there for struct
template)
ans: 0
861.
857.
main()
{
char b;
}node;
main()
{
struct info node1;
node1.i=55;
printf("%d",node1.i);
}
ans: 55 (node is
different from node1)
862.
struct a
{
int i;
int display()
{
printf("hello world\n");
}
};
ans: x = 2 y = 2
866.
main()
{
strcut a vara;
vara.display();
}
ans: functions may not
be a part of a struct or union
863.
int main()
{
int a[20];
int *p,*q,val;
p = &a[0];
q = &a[10];
val = q - p;
printf("p %d ",p);
printf("q %d ",q);
printf("val %d",val);
}
struct a
10
867.
main()
{
struct a structa;
structa.ptr=display;
structa.ptr();
}
ans: Global Edge
(through function
pointers functions can
be implemented in
structures)
864.
union tag
{
int a;
char x;
char y;
}name;
int main()
{
name.a=258;
printf("\n x = %d y = %d
",name.x,name.y);
}
struct key
{
char *word[2];
int count;
char c;
}abc;
int main()
{
printf("\nsize
%d",sizeof(abc));
}
ans: size 11 (pointer
takes 4 bytes)
868.
main()
{
int a;
fun();
printf("%d",a);
a=50;
}
fun()
{
int i;
*(&i+4) = 100;
}
{
int i,j;
i = 06;
j = 09;
printf ("%d %d\n",i,j);
}
main()
{
#define x 5
int b;
b = x;
printf("%d",b);
}
ans: 5
870.
main()
main()
875.
main()
{
int a; #define y 10
a=y;
printf("%d",a);
}
{
int i,j;
i = o6;
j = 09;
printf ("%d %d\n",i,j);
}
#define s -50
main()
{
int s;
#ifdef s
printf("Hell\n");
#else
printf("Heaven\n");
#endif
}
# undef __FILE__
# define __FILE__ "GLOBALEDGE"
main()
{
printf("%s\n",__FILE__);
}
ans: Bad undef directive
syntax
#define s -50
main()
{
int a;
#ifdef s
printf("Hell\n");
#else
printf("Heaven\n");
#endif
}
877.
ans: Hell
873.
How many times can a comment
be nested ?
A)COMMENT_NEST_LIMIT times
B)COMMENT_LIMIT times
C)ONE time
# define LINE
# define NAME "GESL"
main()
{
printf("%d
%s\n",LINE,NAME);
}
# define LINE 1
# define NAME "GESL"
main()
{
printf("%d
%s\n",LINE,NAME);
}
ans: 1 GESL
879.
main()
{
int i=10;
float j=2.5;
printf("%d ",sizeof(j+++i+
int i;
i = 1, 2;
printf("%d", i);
}
printf("%d %f",i,j);
}
ans: 1
+));
885.
ans: 4 10 2.500000
880.
int main()
{
int i = 5;
if(1)
{
static int i;
i++;
printf("%d ", i);
}
printf("%d", i);
}
int i =20;
int maxlen = i;
int main()
{
int j = i;
printf("i=%d , j=%d\n", i ,
j);
}
ans: illegal initialization
error (static and global
variables shoul be
initialized with
constants or constant
expression)
ans: 1 5
886.
881.
int main()
{
int a[4] = {23, 67, 90};
printf("%d", a[3]);
}
ans: 0 (when there are
fewer initializations
remaining elements are
zero)
882.
int main()
{
int i =10;
printf("%d", k);
printf("%d",i);
}
int k = 20;
int main()
{
int i = 1, 2;
printf("%d", i);
}
ans: error (declaration
terminated incorrectly)
int main()
{
int i =10;
extern int k;
printf("%d ", k);
printf("%d",i);
}
int k = 20;
ans: 20 10
883.
int main()
{
int i;
for( i=0;;i++)
{
i = i+2;
break;
printf("%d", i);
}
}
888.
int i =20;
int i,j=10;
int i;
main()
{
int j =20;
printf("i=%d , j=%d\n", i, j);
}
ans: i=20 , j=20
int main()
{
889.
int main()
{
int k=2,i =10;
while(k--)
{
printf("%d ",disp(i));
}
}
disp(int k)
{
static int i=0;
return i=i+k;
}
ans: 18d
896.
main()
{
int i = 24;
printf("%0xd",i);
}
ans: 10 20
890.
ans: 18d
897.
ans: b)
891.
int main()
{
int i =3;
while(i--)
{
int i =10;
printf("%d ",i);
}
}
ans: 10 10 10
892.
int main()
{
char s[] = "hello\0 world";
printf("%s...
%d",s,strlen(s));
}
899.
int main()
{
printf("%%%
}
s","hello");
ans: %hello
894.
struct node_tag
{
int i;
struct node_tag *pt;
};
main()
{
printf("%d",sizeof(node_ta
g));
}
ans: error (struct
keyword is missing)
ans: hello5
893.
struct node
{
int i;
};
main()
{
struct node n1;
printf("%d",n1.i);
}
struct node_tag
{
int i;
struct node_tag *pt;
};
main()
{
printf("%d",sizeof(struct
node_tag));
}
895.
main()
900.
{
int i = 24;
printf("%xd",i);
}
{
node n1;
printf("%d",n1.i);
}
struct
{
int i;
}node ;
906.
main()
(void *) is called
(a)pointer to void
(b)pointer to any data type
(c)generic pointer
(d)None of the above
{
printf("%d",node.i);
}
ans: 0
902.
main()
ans: (c)
907.
main()
{
struct
{
int i;
}node ;
printf("%d",node.i);
}
ans: 19125 (garbage
{
int i=5;
i=i++ * i++;
printf("%d",i);
}
ans: 27
908.
value)
903.
struct tag
{
int i;
};
main()
{
struct tag node;
printf("%d",node.i);
}
{
int i=5;
printf("%d",i++ * i++);
}
ans: 30
909.
struct node_tag
{
int a;
struct node_tag *pt;
};
910.
{
struct node_tag n1;
n1.pt=&n1;
n1.pt->a=5;
printf("%d",n1.a);
}
905.
main()
{
int n;
scanf("%d",n);
}
int main()
{
char *p = "Welcome To
GESL\n";
*(p+10);
fprintf(stderr,"%s",p);
return 'c';
}
ans: Welcome To GESL
main()
ans: 5
main()
int main()
{
char *p = "Welcome To
GESL\n";
*(p+++10);
fprintf(stderr,"%s",p);
return 'c';
}
ans: elcome To GESL
911.
int main(void)
{
puts("hello\0world");
}
ans: hello (\0 null
character is there after hello)
}
912.
union u
{
int ival;
float fval;
char *sval;
}
size of u is?
struct a
{
int x;
float y;
double z;
struct a b;
};
ans: 4 bytes
913.
struct x
{
int i; int j;int k;
};
struct x *p;
struct x arr[3];
p =&arr[0];
p++;
what is p pointing to?
a) pointing to i of arr[0]
b) pointing to j of arr[0]
c) pointing to k of arr[1]
d) pointing to i of arr[1]
int main()
{
;
}
ans: error (undefined
structure a)
917.
struct a
{
int x;
float y;
double z;
struct a *b;
};
ans: d)
914.
struct a
{
int b;
};
int main()
{
;
}
struct b
{
int b;
};
int main()
{
struct a first;
struct b second;
first.b =10;
second = first;
printf("%d",second.b);
}
ans: no error
918.
{
struct b
{
int a;int b;
}c;
int *ptr;
}d;
struct a
int main()
{
d.ptr=&d.c.a;
}
struct a
{
int b;
};
int main()
{
struct a first,second;
first.b =10;
second = first;
printf("%d",second.b);
ans: no error
919.
int main(void)
{
int *intPtr ;
intPtr =
(char*)malloc(sizeof(10));
printf("\n The starting
address is %d \n ",intPtr);
return 0;
}
924.
ans: The starting
address is 2274
f()
{ return 1,2,3; }
main()
920.
int main(void)
{
int intNum1,intNum2,num
= 1,i;
printf("\nEnter first number
\n");
scanf("%d",&intNum1);
printf("\nEnter second
number \n");
scanf("%d",intNum2);
for(i = 0;i<=3;i++)
{
num = intNum1 * intNum2
* num;
}
printf("\n num = %d " ,
num);
return 0;
}
ans: error (second scanf
function reads a value
into a memory location
which may not be user
accessible some times)
921.
int main(void)
{
int a=1,b=0, x;
x = a++ && ++b;
printf("%d %d %d ",a,b,x );
}
{
int i;
i = f();
printf("%d",i );
}
ans: 3
925.
What is the difference between +
+*ip and *ip++ ?
a) both increment value
b) ++*ip increment value and *ip+
+ increment address
c) both increment address
d) ++*ip increment address and
*ip++ increment value
ans: b)
926.
ans: 2 1 1
922.
char *fn();
main()
{
char *s;
s = fn();
printf("%s\n",s );
}
char *fn()
{ return "Hello"; }
928.
main()
{
int i;
for( i=0; i<10-1; i+=2 );
i+= 2;
printf("i = %d\n", i );
}
# define ONE 1
# define TWO 2
# define ONE TWO
//# define TWO ONE
int main (void)
{
printf("ONE = %d, TWO =
%d\n", ONE, TWO );
}
ans: ONE = 2, TWO = 2
929.
ans: i = 12
# define ONE 1
# define TWO 2
//# define ONE TWO
//# define TWO ONE
int main (void)
{
printf("ONE = %d, TWO =
%d\n", ONE, TWO );
}
ans: ONE = 1, TWO = 2
ans: Hello
923.
# define ONE 1
# define TWO 2
func(int x)
{
int val,x;
val = 2;
return(x+ val++);
}
ans: error (multiple
declaration of x)
934.
Where is a variable defined in a
function stores?
ans. Process Swappable
Area
935.
ans: 2 3
936.
main()
{
int i,j;
int arr[4][4] =
{1,2,3,4,5,6,7,8,9,10,11,12,13,14,1
5,16};
for (i=2;i<0;i--)
for (j=2;j<=0;j--)
printf("%d", arr[i][j]);
}
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);
}
void main()
{
int i=0,j=0;
int arr[4][4] =
{1,2,3,4,5,6,7,8,9,10,11,12,13,14,1
5,16};
clrscr();
for (i=2;i>=0;i--)
for(j=2;j>=0;j--)
printf("%d ", *(*(arr+j)+i));
getch();
}
ans: 11 7 3 10 6 2 9 5 1
937.
ans: no output
933.
void main()
{
int ari[] = {1,2,3,4,5};
char arc[] =
{'a','b','c','d','e'};
printf("%d ",&ari[4]&ari[2]);
printf("%d ",&arc[3]&arc[0]);
}
void main()
{
int a=10,b=11;
printf("%d ",a+++b);
printf("%d",a+++b);
}
ans: 21 22
938.
void main()
{
int a;
void c;
}
ans: error (size of c is
unknown)
939.
default: c=0;
}
printf("%d",c);
}
void main()
{
int a;
void *c;
}
main()
{
f(3);
}
ans: no error
940.
void main()
{
int a,b;
a=0;
b=(a=0)?2:3;
printf("%d",b);
}
f(int t)
{
int c;
switch(t)
{
case 2: c=3;
case 3: c=4;
case 4: c=5;
case 5: c=6;
default: c=0;
}
printf("%d",c);
}
ans: 3
942.
f1(int c)
{
printf("%d", c);
}
main()
{
int a=2;
f1(a++);
}
main()
{
f(3);
}
ans: 2
943.
f(int t)
ans: 0
{
switch(t)
{
int c;
case 2: c=3;
case 3: c=4;
case 4: c=5;
case 5: c=6;
default: c=0;
}
printf("%d",c);
}
main()
{
f(3);
}
ans: error (undefined
symbol c)
944.
f(int t)
{
int c;
switch(t);
{
case 2: c=3;
case 3: c=4;
case 4: c=5;
case 5: c=6;
946.
What is the fallacy in the following
program segment?
int *f1()
{
int a=5;
return &a;
}
f()
int *b=f1()
int c=*b;
}
ans: we should not
return address of a auto
variable as its scope will
be lost when function
returns
947.
Give the C language equivalents of
the following
a)Function returning an int pointer
b)Function pointer returning an int
pointer
c)Function pointer returning an
array of integers
d)Array of function pointer
returning an array of integers
952.
int
int
int
int
main()
*x();
*(*x)();
( (*x)() )[];
( (*x[])() )[];
{
int a=1,b=2,c=3;
printf("%d,%d",a,b,c);
}
948.
Bootstrap loader program is a
program belonging to
ans: 1,2
953.
main()
{
int i;
for(i=0; i<=10;i+
+,printf("%d ",i));
}
ans: (a)
ans: 1 2 3 4 5 6 7 8 9 10
949.
void main()
{
int a=3,b=4,c=5;
a=b+c;
c=a+b;
b=a+c;
printf("%d %d %d
",a+b,b+c,c+a);
a=b*c;
c=a*b;
printf("%d %d",a,c);
}
11
954.
{
int a[]={10,20,30,40,50};
fun(a+1);
}
fun(int *p)
{
for(int i=1;i<=3;i++)
printf("%d",*(p+i));
}
void main()
{
printf("\nab\bcd\ref");
}
main()
main()
{
int a[]={10,20,30,40,50};
fun(a+1);
}
fun(int *p)
{
int i;
for( i=1;i<=3;i++)
printf("%d",*(p+i));
}
struct a
{
char b[7];
char *s;
};
struct b
ans: 30 40 50
{
char *t;
struct a y;
};
956.
main()
{
enum day {saturday,
sunday=3,
monday,
tuesday
};
printf("%d
%d",saturday,tuesday);
}
main()
{
struct b q={"Raipur" ,
"Kanpur" , "Jaipur"};
printf("%s %s " , q.t , q.y.s);
printf("%s %s" ,++q.t , +
+q.y.s);
}
ans: 0 5
ans: Raipur Jaipur aipur
aipur
957.
main()
{
int x;
enum day {
saturday,
sunday=-1,
monday,
tuesday
};
x=monday;
printf("%d",x);
}
main()
{
INTEGER p=10;/*line 5*/
printf("%d",p);
}
ans: error (undefined
symbol INTEGER and undefined
symbol p)
963.
ans: 0
958.
main()
{
char
str={'H','E','L','L','O','\0'};
printf("%s/n",str+1);
}
ans: error
964.
main()
{
char
arr[5]={'a','a','b','c','d','e'};
printf("%s",arr);
}
960.
main()
{
printf("\% ");
printf("\\% ");
printf("%% ");
printf("%%%%");
}
ans: % \%
966.
%%
main()
{
printf("%%%%% ");
printf("%%%%%% ");
printf("%");
}
int x;
int *p;
int **p1;
int ***p2;
How to assign each one?
961.
p=&x;
p1=&p;
p2=&p1;
967.
{
int i=3;
while(i>=0)
printf("%d ",i--);
return(0);
}
ans: 3 2 1 0 (loop is
executed 4 times)
ans: (a)
962.
main()
968.
main()
{
int i=10;
printf("%d %d %d ",i,+
+i,i++);
}
ans: 12 12 10
969.
main()
ans: 20 6
974.
main()
{
int x,y,z;
x=2;
y=5;
z=x+++y;
printf("%d %d %d",x,y,z);
}
ans: 3 5 7
970.
{
unsigned int i=3;
while( i >=0)
printf( "%d", i--);
}
ans: infinite loop
975.
# define swap(a,b) temp=a; a=b;
b=temp;
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: 10 0 0
976.
func()
bytes)
971.
{
static int i = 10;
printf("%d",i);
i++;
}
main()
{
char s[10];
xyz(s);
}
977.
func(int *i, int*j)
{
*i=*i * *i;
*j=*j* *j;
}
ans: 10
972.
main()
main()
{
int i=6;
printf("%d",i++*i++);
}
{
int i = 5, j = 2;
func(&i,&j);
printf("%d %d", i, j);
}
ans: 42
ans: 25 4
973.
main()
{
978.
{
p=(char *) malloc(6);
strcpy(p,"hello");
}
void main()
{
char *p="bye";
f(p);
printf("%s",p);
}
ans: bye
979.
ans: 5 5
984.
main()
{
char *a="new";
x(a);
printf("%s",a);
}
ans: error (nonportable
pointer conversion)
980.
985.
986.
982.
void main()
{
void main()
{
double i=0.0;
switch(i)
{
case 0.0:
printf("jgdj");
case 1.0:
printf("ptoy");
break;
default:
printf("hdfv");
}
}
ans: error (switch
expression should be
integer expression or
characters and case
values should be
constants or constat
expression)
void main()
{
char
*s[10]={"welcome","to","india"};
printf("%d",sizeof(s));
}
ans: 40
void main()
{
int *ptr;
p=0;
p++;
printf("%u", p);
}
ans: error (assigning an
absolute address to a
pointer variable is
invalid)
main()
{
int i =1;
switch(i)
{
printf ("first");
i++;
case 1 : printf ("second");
break;
case 2 : printf("");
break;
default : printf("");
break;
}
}
void main()
{
char c[]="123456789";
int i=4;
printf("%c %c", c[i], i[c]);
}
void main()
{
int a=2;
if(a=3!=3)
printf("3");
else
printf("2");
return;
}
p=(char
*)malloc(sizeof(6));
strcpy(p,"HELLO");
}
main()
{
char *p="BYE";
f(p);
printf("%s",p);
}
ans: 2
987.
#define TRUE 0
main()
{
int i=0;
while(TRUE)
{
printf(" %d \n",i);
i++;
}
printf(" %d \n",i);
i++;
}
ans: BYE
992.
ans: 0
988.
main()
{
int a[4]={1,2,3,4};
int *ptr;
ptr=a;
*(a+3)=*(++ptr)+(*ptr+
+);
f(char **p)
{
*p=(char
*)malloc(sizeof(6));
strcpy(*p,"HELLO");
}
main()
{
char *p="BYE";
f(p);
printf("%s",p);
}
ans: HELLO
993.
main()
printf("%d",a[3]);
}
{
char str[5]="hello";
if(str==NULL) printf("string
ans: 4
null");
else printf("string not
989.
f(char *p)
{
p[0]? f(++p):1;
printf("%d ",*p);
}
main()
{
f("abcde");
}
null");
}
ans: string not null
994.
f(char *p)
{
p[0]? f(++p):1;
printf("%c ",*p);
}
main()
{
f("abcde");
}
ans: null null e d c b
(first two are null characters)
991.
f(char *p)
{
void f(int x)
{
int i;
for (i=0;i<16;i++)
{
if(x &0x8000>>i)
printf("1");
else printf("0");
}
}
ans: binary
representation of x
995.
printf("%d ",a);
f(&a);
printf("%d ",a);
}
main()
{
char a[10]="hello";
strcpy(a,\0);
printf("%s",a);
}
struct a
{
int x;
float y;
char c[10];
};
ans: no output
1000.
union b
{
int x;
float y;
char c[10];
};
main()
{
printf("%d
%d",sizeof(a),sizeof(b));
}
ans: error (here sizeof
operator operand
should be type name
not tag name)
997.
void f(int*j)
{
int k=10;
j= &k;
}
main()
{
int i,*j;
i=5;
j=&i;
printf("i=%d ",i);
f(j);
printf("i=%d",i);
}
ans: i=5 =5
1001.
main()
{
int *s = "\0";
if(strcmp(s,NULL)== 0)
printf("\n s is null");
else
printf("\n s is not null");
}
struct a
{
int x;
float y;
char c[10];
};
union b
{
int x;
float y;
char c[10];
};
ans: error
1002.
{
int *s = "";
if(strcmp(s,NULL)== 0)
printf("\n s is null");
else
printf("\n s is not null");
}
main()
{
printf("%d
%d",sizeof(struct a),sizeof(union
b));
}
ans: 16 10
998.
ans: error
1003.
main()
{
char a[10]="hello";
strcpy(a,'\0');
printf("%s",a);
}
main()
1004.
*i=*i * *i;
*j=*j* *j;
}
char *a="new";
x(a);
printf("%s",a);
}
main()
{
int i = 5, j = 2;
func(&i,&j);
printf("%d %d", i, j);
}
ans: 25 4
1005.
a. for(i=0;i<num;i++)
b. for(i=num;i>0;i--)
Assuming no code optimization and
assume that the microprocessor
has flags etc. which one is correct
ans: b (in b zero
flag is tested but in a both
compare instruction and flag
testing will be there)
main()
{
char *a="new";
x(a);
printf("%s",a);
}
1009.
main()
{
char *a="new";
x(a);
printf("%s",a);
}
1010.
ans: new
1007.
#define max 10
main()
{
int a,b;
int *p,*q;
a=10;b=19;
p=&(a+b);
q=&max;
}
ans: error (& must take
address of a memory location)
1011.
main()
{
char S[6]= "HELLO";
printf("%s ",S[6]);
}
unsigned char c;
for ( c=0;c!=256;c++2)
printf("%d",c);
main()
{
char *x="string";
char y[]="add";
char *z;
z=(char *)
malloc(sizeof(x)+sizeof(y)+1);
strcpy(z,y);
strcat(z,x);
printf("%s+%s=%s",y,x,z);
}
ans: 11 12
1018.
+)
{
printf("%d %d", I, j);
}
}
ans: no output
1019.
1020.
void main()
{
int z;
int x = 5;
int y = -10;
int a = 4;
int b = 2;
z = x++ - --y * b /a;
printf("%d",z);
}
ans: 10
ans: (B)
1016.
main()
{
int I,j;
for(I=0, j=I++; j>I; j++, I+
ans:
add+string=addstring
1014.
void func()
{
int x = 0;
static int y = 0;
x++; y++;
printf( "%d--%d ", x, y );
}
int main()
{
func();
func();
return 0;
}
void main()
{
int x[] = { 1, 4, 8, 5, 1, 4 };
int *ptr, y;
ptr = x + 4;
y = ptr - x;
printf("%d",y);
}
ans: 4
1021.
void main()
{
char str[20] = "ENIGMA";
char *p, *q, *r;
p=str;
q=p++;
r=p+3 - (p-q);
printf("%3s %5s", (++p)
+3, r);
}
ans:
1022.
GMA
void main()
{
char str[20] = "ENIGMA";
char *p, *q, *r;
p=str;
q=p++;
r=p+3 - (q-p);
printf("%3s %5s", (++p)
+3, r);
}
ans:
1023.
void *p;
what operation cannot be
performed on p?
ans : arithmetic
operation unless it is properly
typecasted
1027.
main()
{
char **p="Hello";
printf("%s ",p);
printf("%c",*p);
//printf("%c",**p);
}
ans: Hello H
1028.
main()
{
char **p="Hello";
printf("%s ",p);
printf("%c",*p);
printf("%c",**p);
}
{
char str[]="Geneius";
print (str);
}
print(char *s)
{
if(*s)
print(++s);
printf("%c ",*s);
}
(A) No Difference
(B) The 2nd declaration will
not compile
(C) First case Compiler
looks in all default location
and in 2nd case only in the
working directory
(D) Depends on the
Compiler
ans: (C)
1025.
#define FIRST_PART 7
#define LAST_PART 5
main()
main()
{
printf("Genius
%d",fun(123));
}
fun(int n)
{
return (printf("%d",n));
}
ans: strings
1036.
main()
{
char *p = "Oracle India";
p[5] == 'l' ?
printf("Orcle") : printf("India");
}
ans: 123Genius 3
1031.
main()
ans: India
1037.
{
int i=4;
fun(i=i/4);
printf("%d",i);
}
fun(int i)
{
return i/2;
}
main()
{
int i=5;
recursive(i);
}
recursive(int u)
{
if(u > 0 )
recursive(u-1);
printf("%d ", u);
}
ans: 1
ans: 0 1 2 3 4 5
1032.
main()
{
printf("\"NITK %
%SURATHKAL%% !\"");
}
1038.
char *(*(*x() ) [] ) ()
ans: x is a function
returnting pointer to
array of pointers to
functions returning
character pointers
ans: NITK
%SURATHKAL% !
1033.
main()
1039.
{
printf("\"NITK \
%SURATHKAL\% !\"");
}
ans: NITK
%SURATHKAL% !
1034.
main()
ans: 2
1040.
{
char str[7]="strings";
printf("%s",str);
}
ans: strings.(till it
encounters null
character. While
printing if it accesses
inaccessible memory
location error will come)
1035.
main()
{
char str[8]="strings";
printf("%s",str);
}
main()
{
const int MAX=10;
enum a {a,b,MAX};
printf("%d",MAX);
}
ans: error (multiple
declaration of MAX)
1041.
1048.
main()
{
int x=10,y,z;
y=--x;
z=x--;
printf("%d %d %d",x,y,z);
}
1043.
void *p;
what operation cannot be
performed on p?
ans: 8 9 9
1049.
{
int i;
int
marks[]={100,90,75,90,80};
for (i=0;i<4;i++)
disp(&marks[i]);
}
disp(int *n)
{
printf("%d ",*n);
}
ans : arithmetic
operation unless it is properly
typecasted
1044.
main()
{
int i=4;
fun(i=i/4);
printf("%d",i);
}
fun(int i)
{
return i/2;
}
main()
ans: 100 90 75 90
1050.
main()
{
int arr[]={1,2,3,4,5,6,7};
int *I,*j;
I=&arr[1];
j=&arr[5];
printf("%d %d",*j+*I,*j-*I);
}
ans: 1
1045.
main()
{
int a=500,b,c;
if(a>400)
b=300; c=2--; printf("%d
%d",b,c);
}
main()
{
int n=2,sum=5;
switch(n)
{
case 2:sum=sum-2;
case 3:sum*=5;
break;
default:sum=0;
}
printf("%d",sum);
}
main()
{
char c1='a',c2='Z';
if (c1=='a'or c2=='z')
printf("welcome");
}
ans: error (for ORing ||
symbol should be used)
ans: 15
1047.
main()
{
int i;
for(i=0;i<=10;i++);
printf("%d ",i);
}
ans: 11
1052.
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);
}
}
1055.
func(int i)
{
if(i%2) return 0;
else return 1;
}
main()
{
int i=3;
i=func(i);
i=func(i);
printf("%d",i);
}
ans: 1
ans: 16 21
1056.
1053.
main()
{
int i=0;
for(i=0;i<20;i++)
{
switch(i)
{
default:
i+=4;
break;
case 0:
i+=5;
case 1:
i+=2;
case 5:
i+=5;
}
printf("%d ",i);
}
}
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());
}
ans: Answer is:Second
String
1057.
main()
{
int a[5]={1,3,6,7,0};
int *b;
b=&a[2];
printf("%d",b[-1]);
}
ans: 12 17 22
1054.
main()
{
int i=0;
for(i=0;i<20;i++)
{
switch(i)
{
default:
i+=4;
case 0:
i+=5;
case 1:
i+=2;
case 5:
i+=5;
}
printf("%d ",i);
}
}
ans: 12 29
ans: 3
1058.
main()
{
int i = 5;
printf("%d\n", i--*i++);
}
ans: 20
1060.
main()
for (;;);
{
if(i==1)
{
printf("%d",i);
exit();
}
}
}
{
int i = 5;
printf("%d\n", i++*i--);
}
ans: 30
1061.
main()
{
int i = 5;
printf("%d %d", i,i++*i--*i+
+);
}
1066.
ans: 6 150
1062.
main()
{
char ch='a';
printf("%d ",ch);
printf("%d",((int)ch)++);
}
ans: error (lvalue
required)
1063.
int main()
{
int i;
int array1[10],
array2[10]={1,2,3,4,5,6,7,8,9,10};
int *ep, *ip2 = &array2[0];
int *ip1 = &array1[0];
for(ep = &array1[9]; ep >=
ip1; ep--)
*ep = *ip2++ ;
for(i=0;i<10;i++)
printf("%d ",array1[i]);
}
void main()
{
char *p ;
p = (char*)malloc(100);
strcpy(p,"Oracle India");
(p[5] == 'l') ?
printf("Oracle") : printf("India");
}
ans: India
1068.
const int n = 7;
int a[n];
main()
{
;
}
int main()
{
char string[100];
char *p;
gets(string);
for(p = string; *p != '\0';
p++);
printf("%d", p - string);
}
void main()
{
int a=5,b,i;
int func(int y);
for(i = 0;i < 5;i++)
{
a = b = func(a);
printf("%d ",b);
}
}
int func(int y)
{
static int x = 0;
x++;
y = y + x;
return(y);
}
ans: 6 8 11 15 20
main()
{
int i=1 ;
1069.
void main()
{
char i;
for(i=0;i<=256;i++)
printf("%d",i);
}
ans: infinite loop
1070.
void main()
{
int ret,I = 10;
ret = func1(I);
printf("%d",ret);
}
int func1(int d)
{
int ret1;
ret1 = func2(--d);
return(ret1);
}
ans: 4
1077.
int func2(int y)
{
return(++y);
}
d-1071.
void main()
{
char buffer[10] =
{"Genesis"};
printf(" %d ", &buffer[4](buffer));
}
void main()
{
char str[20];
strcpy(str,"Oracle India");
printf("%c",str[10]);
}
void main()
{
struct a
{
char ch[10];
char *str;
};
struct a
s1={"Hyderabad","Bangalore"};
printf("\n%c%c
",s1.ch[0],*s1.str);
printf("%s
%s",s1.ch,s1.str);
getch();
}
ans: HB Hyderabad
Bangalore
ans: i
1078.
1072.
void main()
{
int I=0,j=1;
printf("%d %d",--I ,j++);
}
ans: -1 1
1073.
1074.
#define max 20
printf ("%d", ++max);
ans: 6
1079.
void main()
{
int i,j,k;
for(i=0;i<3;i++)
k=sum(i,i);
printf("\n%d",k);
getch();
}
sum(s,t)
{
static int m;
m+=s+t;
return m;
}
void main()
{
int i;
for(i=1;i<6;++i)
switch(i)
{
case 1:
case 2: printf("%d,",i+
+);break;
case 3: continue;
case 4: printf("%d,",i);
}
printf("%d",i);
getch();
}
getch();
}
ans: 10
1084.
ans: 1,4,6
1080.
void main()
{
char s[]="oracle is the
best";
char t[40];
char *ss,*tt;
while(*tt++=*ss++);
printf("%s",t);
getch();
}
ans: core dump
(Garbage value)
1081.
void main()
{
int
j[10]={9,7,5,3,1,2,4,6,9};
int i=1;
clrscr();
for(;i<9;i++)
printf("%d ",--j[i++]);
getch();
}
ans: 6 2 1 5
1082.
void main()
{
int i,j,k,n=5;
clrscr();
for(i=5;i>0;i--)
{
j=1<i;
k=n&j;
k==0?
printf("0"):printf("1");
}
getch();
}
ans: 11110
1083.
union
{
int a;
char b;
char c[10];
}u1;
void main()
{
int l=sizeof(u1);
printf("%d",l);
void main()
{
struct a
{
int i;
char *st1;
};
typedef struct a ST;
ST *str1;
str1=(ST*)malloc(100);
str1->i=100;
strcpy(str1->st1,"Welcome
to Oracle");
printf(" %d %s\n",str1>i,str1->st1);
getch();
}
ans: 100 Welcome to
Oracle
1085.
void main()
{
int i,j,k;
i=2;
j=4;
k=i++>j&2;
printf("%d",k);
if(++k && ++i<--j|| i++)
{
j=++k;
}
printf(" %d %d %d",i,-j--,k);
getch();
}
ans: 0 -5 -2 2
ans: C
1087.
void main()
{
int i,j=20;
clrscr();
for(i=1;i<3;i++)
{
printf("%d,",i);
continue;
printf("%d",j);
break;
}
getch();
}
ans: 1,2,
1088.
1089.
ans: error
1091.
main()
{
int A=5,x;
int fun(int *, int);
x=fun(&A,A);
printf("%d",x);
}
int fun(int *x, int y);
{
*x=*x+1;
return(*x*y);
}
ans: error (; in function
definition)
1093.
main()
{
int A=5,x;
int fun(int *, int);
x=fun(&A,A);
printf("%d",x);
}
main()
{
char *p="abc";
char *q="abc123";
while(*p=*q)
{
printf("%c %c ",*p,*q);
getch();
}
}
ans: a a a a a a a a a a
a.(infinite loop)
1090.
main()
{
int A=5,x;
int fun(int *, int);
x=fun(&A,A);
printf("%d",x);
}
int fun(int *x, int y)
{
*x=*x+1;
return(*x*y);
}
ans: 30
1095.
if (x=0)
printf ("Value of x is 0");
else
printf ("Value of x is not
main()
{
int i;
int x[]={0,0,0,0,0};
for(i=1;i<=4;i++)
x[x[i]]++;
for(i=0;i<5;i++)
printf(" %d",x[i]);
}
0");
}
ans: Value of x is not 0
1100.
ans: 4 0 0 0 0
1096.
main()
{
int i,j,count;
int a[3][4] = { -1,2,3,4,5,6,7,-8,9,10,11,12};
count=0;
for(i=2;i<1;i--)
{
for(j=3;j<1;j--)
{
if(a[i][j]<1)
count+=1;
}
}
printf("%d",count);
}
ans: 18 4
1101.
ans: 0
1097.
int sum,count;
void main(void)
{
for(count=5;sum+=-count;)
printf("%d ",sum);
}
1102.
void main(void)
{
int i;
for(i=2;i<=7;i++)
printf("%5d",fno());
}
fno()
{
static int f1=1,f2=1,f3;
return(f3=f1+f2,f1=f2,f2=f
3);
}
ans: 2 3 5 8 13 21
1099.
display()
{
printf (" Hello World");
return 0;
}
void main (void)
{
int (*func_ptr)();
func_ptr = display;
(* func_ptr)();
}
ans: Hello World
ans: 4 7 9 10 10 9 7 4
1098.
1103.
char *rev();
void main(void)
{
printf ("%c", *rev());
}
char *rev ()
{
char dec[]="abcde";
return dec;
}
1108.
ans: a (another ans:
prints garbage, address
of the local variable
should not returned)
1104.
void main(void)
{
int i;
static int k;
if(k=='0')
printf("one");
else if(k== 48)
printf("two");
else
printf("three");
}
ans: 50
1109.
ans: three
1105.
void main(void)
{
enum sub{chemistry,
maths, physics};
struct result
{
char name[30];
enum sub sc;
};
struct result my_res;
strcpy
(my_res.name,"Patrick");
my_res.sc=physics;
printf("name: %s
",my_res.name);
printf("pass in subject:
%d\n",my_res.sc);
}
1110.
ans: I M
1107.
1111.
main()
{
int x;
float y;
y = *(float *)&x;
}
main()
{
char *p = "MISTRAL";
printf ("%c\t", *(++p));
p -=1;
printf ("%c\t", *(p++));
}
ans: no output
int main()
{
char *a= "Novell";
char *b;
b=malloc(10*sizeof(char));
memset(b,0,10);
while(*b++=*a++);
printf("%s",b);
getch();
return 0;
}
ans: no output
1113.
int *(*p[10])(char *)
1120.
main()
{
char a[2];
*a[0]=7;
*a[1]=5;
printf("%d",&a[1]-a);
}
main()
{
printf("hello"):
main();
}
ans: hellohello.(prints
recursively till stack overflows)
1115.
char a[]="hellow";
char *b="hellow";
char c[5]="hellow";
printf("%s %s %s ",a,b,c);
printf("
",sizeof(a),sizeof(b),sizeof(c));
}
ans: %s is a string is a
string
1116.
main()
{
printf("%u",-1);
}
ans: 10 10 10 10.000000
1123.
ans: b)
1118.
main()
{
float value=10.00;
printf("%g %0.2g %0.4g
%f",value,value,value,value);
}
ans: 65535
a)stored in swap
b)stored in stack and poped out
after function returns
c)stored in data area
d)stored in disk
main(){
main()
{
printf(5+"facsimile");
}
ans: mile
ans. [iii]
1124.
main()
{
int i=10,j;
for(j=0;j<1;j++)
{
int i=20;
printf("%d ",i);
}
printf("%d",i);
}
ans: 20 10
1125.
main()
{
int i;
printf("%d",i);
}
extern int i=20;
main()
{
extern int i;
printf("%d",i);
}
int i=20;
1132.
of 2.
ans: 20
1127.
main()
{
int n=6;
printf("%d",n)
;
}
1133.
1134.
ans: 6
1128.
main()
{
int arr[5]={2,4};
printf("%d %d %d
\n",arr[2],arr[3],arr[4]);
}
ans: 0 0 0
1129.
main()
{
struct e
{
char name[20];
int a;
float b;
};
struct e ast={"Hell"};
printf("%d %f
\n",ast.a,ast.b);
}
recursive reverse(ptr)
if (ptr->next == NULL)
return ptr;
temp = reverse(ptr->next);
temp->next = ptr;
return ptr;
end
1135.
1136.
ans: 0 0.000000
1130.
1139.
putc(array[c - 'a']);
}
1142.
1143.
int size)
{
int current, insert = 1;
for (current=1; current < size;
current++)
if (p[current] != p[insert-1])
{
p[insert] = p[current];
current++;
insert++;
} else
current++;
return insert;
}
1141.
****1144.
Under what circumstances
can one delete an element from a
singly linked list in constant time?
ans: If the list is circular and there
are no references to the nodes in
the list from anywhere else! Just
copy the contents of the next node
and delete the next node. If the list
is not circular, we can delete any
but the last node using this idea. In
that case, mark the last node as
dummy!
****1145.
Given a singly linked list,
determine whether it contains a loop or
not.
ans: (a) Start reversing the list. If
you reach the head, gotcha! there
is a loop!
But this changes the list. So,
reverse the list again.
(b) Maintain two pointers, initially
pointing to the head. Advance one
of them one node at a time. And
the other one, two nodes at a time.
If the latter overtakes the former at
any time, there is a loop!
p1 = p2 = head;
do {
p1 = p1>next;
x=(0xff00ff00&x)>>8|
(0x00ff00ff&x)<<8, \
p2 = p2>next->next;
} while (p1 !=
x=(0xf0f0f0f0&x)>>4|
(0x0f0f0f0f&x)<<4, \
p2);
****1146.
Given a singly linked list,
print out its contents in reverse
order. Can you do it without using
any extra space?
ans: Start reversing the list. Do this
again, printing the contents.
x=(0xcccccccc&x)>>2|
(0x33333333&x)<<2, \
x=(0xaaaaaaaa&x)>>1|
(0x55555555&x)<<1)
1150. Compute the number of ones in an
unsigned integer.
****1147.
Reverse a singly linked list
recursively. function prototype is
node * reverse (node *) ;
ans:
#define count_ones(x)
\
ans:
node * reverse (node * n)
{
node * m ;
(x=(0xaaaaaaaa&x)>>1+(0x55555555&x)
,\
if (! (n && n ->
x=(0xcccccccc&x)>>2+(0x33333333&x), \
next))
return n ;
x=(0xf0f0f0f0&x)>>4+(0x0f0f0f0f&x), \
m = reverse (n ->
next) ;
n -> next -> next =
x=(0xff00ff00&x)>>8+(0x00ff00ff&x), \
n;
n -> next = NULL ;
return m ;
}
x=x>>16+(0x0000ffff&x))
1151. Compute the discrete log of an
unsigned integer.
****1148.
Given a singly linked list,
find the middle of the list.
HINT. Use the single and double
pointer jumping. Maintain two
pointers, initially pointing to the
head. Advance one of them one
node at a time. And the other one,
two nodes at a time. When the
double reaches the end, the single
is in the middle. This is not
asymptotically faster but seems to
take less steps than going through
the list twice.
1149. Reverse the bits of an unsigned
integer.
ans:
#define discrete_log(h) \
(h=(h>>1)|(h>>2), \
h|=(h>>2), \
h|=(h>>4), \
h|=(h>>8), \
h|=(h>>16), \
h=(0xaaaaaaaa&h)>>1+(0x55555
555&h), \
h=(0xcccccccc&h)>>2+(0x333333
33&h), \
h=(0xf0f0f0f0&h)>>4+(0x0f0f0f0f
&h), \
ans:
h=(0xff00ff00&h)>>8+(0x00ff00ff
&h), \
h=(h>>16)+(0x0000ffff&h))
#define reverse(x)
\
(x=x>>16|(0x0000ffff&x)<<16,
1159.
1160.
int *a;
char *c;
*(a) = 20;
*c = *a;
printf("%c",*c);
ans: #define
power_of_two(x) \ ((x)&&(~(x&(x1))))
1155.
1156.
1157.
1158.
1162.
1163.
1164.
1165.
#define i sizeof(i)
main()
{
printf("%d",i);
}
ans: error (undefined
symbol i)