150. main()
{
printf("Hello\n");
fork();
printf("Hi\n");
}
Justify:
Answer :
OBJECTIVE TYPE QUESTIONS
151. what does exit() do?
Answer : come out of executing programme.
152. In 'o' how are the arguments passed?
Answer : by value.
153. Find the prototype of sine function.
Answer : extern double sin(double)
154. Scope of a global variable which is declared as static?
Answer : File
155.the function strcmp(str1,str2) returns
Answer :
156. n=7623
{
temp=n/10;
result=temp*10+ result;
n=n/10
}
Answer : 3267
157. when a function is recursively called all ,automatic variables are
Answer : stored in stack
158. what is the value of 'i'?
i=strlen("Blue")+strlen("People")/strlen("Red")-strlen("green")
Answer : 1
159. what does " calloc" do?
Answer : A memory allocation and initialising to zero.
160. Using pointer, changing A to B and B to A is Swapping the function
using two address and one temperory variable. a,b are address, t is
temporary variable. How function look like?
Answer : swap(int *, int *, int )
161. Pick up the correct function declaration.
1.void *[] name();
2 void int[][] name();
3 void ** name();
4 none of the above.
Answer :
162. how does the C compiler interpret the following two statements
p=p+x;
q=q+y;
a. p=p+x;
q=q+y
b. p=p+xq=q+y
c. p=p+xq;
q=q+y
d. p=p+x/q=q+y
Answer :
163. main()
{
int i=0;
for( ;i++; )
printf("%d",i);
}
a. Finite Loop
b. Infinite loop
c. one time loop
d. none of the above
Answer :
164. If i = i * 16;
Which of the following is a better approach to do the operation
A) Multiply i by 16 and keep it
B) Shift left by 4 bits
C) Add i 16 times
D) None of the above
Answer :
165. If i=5, what is the output for printf( " %d %d %d", ++i,i,i++);
a) 5,6,7
b) 6,6,7
c) 7,6,5
d) 6,5,6
Answer :
166. How many bytes of memory will the follwing arrays need ?
(a) char s[80] ans: 80.
(b) char s[80][10] ans: 800.
(c) int d[10] ans: 20.
(d) float d[10][5] ans: 200.
167. which of the following is the correct declaration for the function main() ?
Answer : main( int , char *[])
168. if ptr is defined as
int *ptr[][100];
which of the following correctly allocates memory for ptr?
Answer : ptr = (int *)(malloc(100* sizeof(int));
169. One pointer diff is given like this:
int *(*p[10])(char *, char*)
find the meaning.
Answer :
170. char *a[4]={"jaya","mahe","chandra","buchi"};
what is the value of sizeof(a)/sizeof(char *)
Answer :
171. What is the value of the following expression?
i = 1;
i << 1 % 2
a) 2
b)1
c) 0
172. What is the value of the following expression?
i = 1;
i = (i <<= 1 % 2)
a) 2
b) 0
c) erroneous syntax
Answer :
173. C allows
a) only call by value
b) only call by reference
c) both
d) only call by value and sometimes call by reference
Answer :
174. The following statement is
" The size of a struct is always equal to the sum
of the sizes of its members"
a) valid
b) invalid
c) can't say
Answer :
175. How many x's are printed?
for (i = 0, j = 10; i < j; i++, j--)
printf ("x");
a) 10
b) 5
c) 4
d) none
176. int *i;
float *f;
char *c;
which are the valid castings?
i) (int *) &c
ii) (float *) &c
iii) (char *) &i
Answer :
177. int i = 20;
printf ("%x", i);
what is the output?
a) x14
b) 14
c) 20
d) none of the above
178. void (*((int, void (*)())));
Meaning :
179. Max value of SIGNED int
Answer :
180. One pointer diff is given like this:
int *(*p[10])(char *, char*)
asked to find the meaning.
Answer :
ADDITIONAL PROGRAMS
POINTERS
1. What do the following statements indicate. Explain.
int(*p)[10]
int*f()
int(*pf)()
int*p[10]
Refer to:
-- Kernighan & Ritchie page no. 122
-- Schaum series page no. 323
2. void main()
{
char *s="\12345s\n";
printf("%d",sizeof(s));
}
Answer: 6
3. #include<malloc.h>
char *f()
{
char *s=malloc(8);
strcpy(s,"goodbye");
}
main()
{
char *f();
printf("%c",*f()='A');
}
Answer:
4. void main()
{
int count=10,*temp,sum=0;
temp=&count;
*temp=20;
temp=∑
*temp=count;
printf("%d %d %d ",count,*temp,sum);
}
Answer: 20 20 20
5. what is alloca()
Answer : It allocates and frees memory after use/after getting out of scope
6. void main()
{
char *s[]={ "dharma","hewlett-packard","siemens","ibm"};
char **p;
p=s;
printf("%s",++*p);
printf("%s",*p++);
printf("%s",++*p);
}
Answer:
"harma" (p->add(dharma) && (*p)->harma)
"harma" (after printing, p->add(hewlett-packard) &&(*p)->harma)
"ewlett-packard"
7 . What is int *p(char (*s)[])
Answer:: p is a function which is returning a pointer to integer
which takes arguments as pointer to array of characters.
8. while((*p++=*q++)!=0){}
is equal to
Answer:
9. int *x[](); means
Answer:
10. int a=1; b=2; c=3; *pointer;
pointer=&c;
a=c/*pointer;
b=c;
printf("a=%d b=%d",a,b);
a). a=1 b=3
b) a=3 b=3
c)a= 3 b=2
d) error
Answer:
11. if the following program
main(int size of ,char *arg[])
{
while(size of arg) printf("%s",arg[--size of arg)
}
is run from the command line as myprog jan feb mar apr
what would be the o/p
a)myprog jan,feb,mar,apr
b)rev
c)jan,feb,mar,apr
d)error
Answer:
12. main()
{
char *p='a';
int *i=100/*p;
}
what will be the value of *i= 1
1.03
cannot be defined.
13. char huge* near* far* ptr1;
char near* far* huge* ptr2;
char far* huge* near* ptr3;
char near* far* huge* ptr4;
printf("%d%d%d%d",sizeof(ptr1),sizeof(ptr2),sizeof(ptr3),sizeof(ptr4));
What is the output of the above program?
a. 4242
b. 1111
c. 4424
d. 4444
Answer:
14. Which of the following statement will make program work:
main ()
{
int *! = 10 , *j=20;
i=i*j;
}
A)Replace i = i*j; as i = (int) ((int) i * (int)j);
B)No error
C)Replacei= i*j;as i = (int*) ((int)i*(int)j);
D)Replace i+i*j ; as i = (int) i* (int)j;
Answer:
15. #include<stdio.h>
main()
{
char buff[] = "this is a test";
int i, *ptr;
ptr = (int*)buff;
for (i=0;*ptr; i++);
printf("%c",*ptr++);
}
The following will be the output
A) This is a test
B) It'll print junk
C) Compilation error
D) None of the above
Answer:
16. Study the following program
# include <stdio.h>
char *c[] ={
"FILE",
"EDIT",
"SEARCH",
"COMPILE",
};
HAR **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);
}
The output of this program is
A) SEARCHFILEEDITCOMPILE
B) SEARCHCOMPILEEDIT
C) SEARCHEPILEDIT
D) None of the above
Answer:
17. main()
{
char a[2];
*a[0]=7;
*a[1]=5;
printf("%d",&a[1]-a)
}
Answer:
may be 1.(illegal initialization)
18. char *p="abc";
char *q="abc123";
while(*p=*q)
{
print("%c %c",*p,*q);
}
a. aabbcc
b. aabbcc123
c. abcabc123
d. infinate loop ( this may be correct)
Answer:
19. One question is given, long one, to find the answer U should be familiar
with the operation as follows
int *num={10,1,5,22,90};
main()
{
int *p,*q;
int i;
p=num;
q=num+2;
i=*p++;
print the value of i, and q-p, and some other operations are there.
}
how the values will change??
Answer:
MACROS
20. For the following C program
#define AREA(x)(3.14*x*x)
main()
{
float r1=6.25,r2=2.5,a;
a=AREA(r1);
printf("\n Area of the circle is %f", a);
a=AREA(r2);
printf("\n Area of the circle is %f", a);
}
What is the output?
Answer:
Area of the circle is 122.656250
Area of the circle is 19.625000
21. #define one 0
#ifdef one
printf("one is defined ");
#ifndef one
printf("one is not defined ");
Answer: "one is defined"
22. #define MAX(x,y) (x)>(y)?(x):(y)
{
int i=10;
j=5;
k=0;
k=MAX(i++,++j);
printf(%d %d %d %d,i,j,k);
}
Answer: 10 5 0
23. #define PRINT(int) printf("int=%d",int);
main()
{
int x,y,z;
x=03;y=-1;z=01;
PRINT(x^x);
z<<=3;PRINT(x);
y>>=3;PRINT(y);
}
Answer:
24. #define scanf "%s is a string"
main()
{
printf(scanf,scanf);
}
a) Invalid use of scanf
b) %s is a string
c ) %s is a string %s is a String
d) %s is a string is a String.
Answer:
25. What is the output generated for the following code
#define square (a) (a*a)
printf("%d",square(4+5));
a) 81
b) 4
c) 29
d) None of the above
Answer:
26. output of the program?
#define prn(a) printf("%d",a)
#define print(a,b,c) prn(a), prn(b), 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);
}
Answer: 3 4 2
27. #define void int
int i=300;
void main(void)
{
int i=200;
{
int i=100;
print the value of i;
}
print the value of i
}
what is the output?
Answer: may be 100 200
0 comments:
Post a Comment