Professional Documents
Culture Documents
C Multiple Choice
C Multiple Choice
Ans: C
Ans: D
For(/*initiulization*/;/*condition*/;/*operation*/)
i=i+1
i+= 1
i+=i+1
5
.
6
Ans: B
Ans: c
8.
Ans: B
10.
#include <stdio.h>
int main(void) {
int a=25;
int *ptr;
ptr=&a;
*ptr=50;
printf("%d", a);
return 0;
#include <stdio.h>
int main(void) {
int arr[]={11,21};
int *ptr;
ptr = arr;
*ptr = *ptr+1;
ptr++;
*ptr = *ptr+1;
return 0;
}
11.
Ans: c
%o ?
12.
Ans: B
13.
Ans: A
Ans: B
For(x=0,y=10;x<=10&&y>=9;x++,y--)
15.
Ans: D
Another Question:
Int *parr;
Parr = arr;
Ans: A
Ans: C
18.
Ans: A
01010
10100
So 10&20 is 0
Ans: D
20.
Ans: A
Ans: D
Ans: B
? : conditional or ternary operator
23.
Ans: A
24.
Ans: A
Since compiler will not take 0.1 exactly as 0.1, and will be slightly different
25.
Ans: B
(printf does not belong to for loop, reason is for loop ends where ; is used with fro)
ANs: D
27.
Ans: B
28.
Ans: B
Ans:B
Ans: c
32.
Ans: c
And / has high precedence, both have same precedence, associativitivity is left to right
33.
Ans: D
35.
Ans: B
36.
Ans: C
38.
Ans: B
39.
Ans: C
40.
Ans: C
Ans: B
43.
Ans: A
Ans: c
Though you can’t store function in struct and union, function pointer can be a member of struct or
union
45.
ANs: D
46.
ANs: C
48.
Ans: A
char p = 1
Total s ize is 21
49.
Ans:dbye
50.
ANs: c
51.
Ans:
1 60
2 80
3 40
4 70
…..
52.
Ans:
3 60
4 80
5 40
….
53.
6 60
6 80
6 40
…
54.
Ans: 3 60
3 80
3 40
55.
ANs: D
56.
Ans:
11759
.3 .3 .4 .2 .6
57.
4
8
58.
Ans: D
%x-print in hexadecimal
59.
Ans: C
60.
Ans: D
Ans: C
A=!(1)&&++b;
A=0
C = c+(a+b--)
C= 1+(0+2) = 3
B =1
62.
Ans: D
63.
Ans: B
Ans: B
65.
Ans: A
66.
Ans: D
Ans: D
68.
Ans:c
69.
Ans: D
# Is stringize operator
Using stringize operator we can convert some text into string without using any quotes
ANs: B
71.
Ans: D
Ans: c
73.
Ans:B
74.
Ans: d
Ans:c
76.
Ans:
P=2
10 – size 3 bits = 2
C=-6
1010 – size 3 bits = 2
M=5
77.
Ans:b
78.
Ans:b
Ans: C
80.
Ans: D
0,1,2,3,4
81.
Ans: C
82.
Ans: B
83.
Ans: D
Ans: A
85.
Ans: B
86.
Ans: A
Ans: 8
88.
Ans: 0
Ans:
90.
Ans: B
91.
Ans: C
A is aasigned to 5
92.
Ans: A
93.
Ans: A
Ans: A
95.
Ans: D
Ans: D
Ascii value of a is 97
97.
Ans: C
98.
Ans:
99.
Ans:C
(b+1)[5] is b[6]
100.
Ans: B
Pointers Set:
101.
1. #include <stdio.h>
2.
3. int main(void) {
4. int i = 0;
5. ++i++;
6. printf("%d",i);
7. return 0;
8. }
102.
#include <stdio.h>
int *fun();
int main(void) {
int *myptr;
myptr = fun();
printf("%d", *myptr);
return 0;
int *fun()
return ptr;
103.
Int tmp;
tmp = *p;
*p = *q;
*q = tmp;
Make necessary changes and call above function to swap two numbers
104.
a) Increment operator
b) -> operator
c) Function pointer
d) Linked list
Ans: c
#include <stdio.h>
int *fun();
int main(void) {
int *ptr = (int *)malloc(sizeof(int));
*ptr = 25;
printf("%d", *ptr);
free(ptr);
return 0;
}
int myfun()
return 0;
Int main()
Int (*fptr)();
fptr = myfun;
fptr();
return 0;
Also, explore
#200.
1. #include <stdio.h>
2.
3. int main(void) {
4.
5. int i=0,j=10;
6. /*
7. inititlization, operation
8. */
9. for(i=0,j=10;i<=10&&j>=0;i++,j--)
10. {
11. printf("%d,%d\n",i,j);
12. }
13.
14. return 0;
15. }
#201.
#include <stdio.h>
int main(void) {
int i=0,j=10;
/*
inititlization, operation
*/
for(i=1;i<=5;i++)
for(j=1;j<=10;j++)
printf("%d X %d = %d\n",i,j,i*j);
printf("\n\n");
return 0;
#202.
#include <stdio.h>
int main(void) {
int arr[] = {11,22,23,21,63,52,12};
int *ptr;
ptr = arr;
printf("%d\n", *ptr);
ptr = ptr + 1;
printf("%d", *ptr);
return 0;
#205.
#include <stdio.h>
struct employee{
int empid;
char *name;
float salary;
char *addr[4];
};
int main(void) {
emp[0].name = "kumarEg";
emp[0].salary = 123.4;
emp[0].addr[0] = "Banaglore";
return 0;
#206.
#include <stdio.h>
struct employee{
int empid;
char *name;
float salary;
char *addr[4];
};
int main(void) {
struct employee emp;
sptr = &emp;
(*sptr).empid = 1;
sptr->name = "kumarEg";
sptr->salary = 123.4;
sptr->addr[0] = "Banaglore";
return 0;
#207.
for(i=0;i<len-1;i++);
printf("check:%c\n", sptr->name[i]);
printf("%d", **pptr);
#210.
#include <stdio.h>
int main(void) {
int arr[] = {11,21,2,65,23,31};
printf("%d", *arr);
return 0;
}
#211.
/* CALL BY VALUE */
int main(void) {
int arr[] = {11,21,2,65,23,31};
int num = 25;
/*printf("%d", *arr); */
fun(num);
printf("in main() %d", num);
return 0;
}
fun(int i)
{
printf("(in fun() number is %d\n", i);
i++;
return;
}
#212.
#include <stdio.h>
/* CALL BY Reference */
int main(void) {
int arr[] = {11,21,2,65,23,31};
int num = 25;
/*printf("%d", *arr); */
fun(&num);
printf("in main() %d", num);
return 0;
}
fun(int *pi)
{
printf("(in fun() number is %d\n", *pi);
(*pi)++;
return;
}
#213.
#include <stdio.h>
/*printf("%d", *arr); */
fun(arr);
printf("in main() %d", arr[0]);
return 0;
}
fun(int arrp[])
{
arrp[0] = 11111;
return;
}
#215.
int arr[10];
a)Array has fixed number of elements
b)difficult to remove/add elements in between in run time
c)Accessing of any element is very fast by using index
d) all element stored sequentially in memory
LinkedList:
Number of elements can be added/removed dynamically
Accessing of elements is slower
elements are scattered across memory
void func()
{
printf("This is a function");
}
int main(void) {
/*void (*pfunc)(int, int);*/
void (*pfunc)();
pfunc = func;
pfunc();
return 0;
}
void func()
{
printf("This is a function");
}
int main(void) {
void *vptr;
int i=35;
float f=23.1;
vptr = &i;
printf("%d\n", *(int *)vptr);
vptr = &f;
printf("%f", *(float *)vptr);
exit(0);
void (*pfunc)();
pfunc = func;
pfunc();
return 0;
}
#302.
Void * casted to ptr to function
#include <stdio.h>
void func()
{
printf("This is a function");
}
int main(void) {
void *vptr;
int i=35;
float f=23.1;
vptr = &i;
printf("%d\n", *(int *)vptr);
vptr = &f;
printf("%f", *(float *)vptr);
vptr = func;
((void (*)())vptr)();
return 0;
}
union abc{
int i; /* 4 */
float f; /* 4 */
char ca[20]; /* 20 */
};
int main(void) {
union abc uabc;
printf("%d\n", sizeof(union abc));
uabc.i = 25;
printf("%d\n", uabc.i);
uabc.f = 34.21;
printf("%d", uabc.i);
return 0;
}
pi++;
printf(*pi);
#310. malloc
#include <stdio.h>
int main(void) {
int *ptr;
ptr = (int *)malloc(sizeof(int));
*ptr = 28;
printf("%d", *ptr);
free(ptr);
return 0;
}
#311. Calloc eg
int main(void) {
int *ptr;
ptr = (int *)calloc(sizeof(int)/* size of one block*/, 1/* number of blocks*/);
*ptr = 28;
printf("%d", *ptr);
free(ptr);
return 0;
}
#312. Realloc
#314.
#include – to include header file
#define – to define macro
#if – conditional compilation
#elif – conditional compilation
#else - conditional
#endif
#ifdef
#ifndef
#undef
#pragma – instructing compiler
#error – raise error during preprocessing
# - strignignzing operator
## - tokenizer
#ifdef x
printf("hello\n"); // this is compiled as x is
defined
#else
printf("bye\n"); // this isn't compiled
#endif
#if x==10
printf("hello\n"); // this is compiled as x is
#elif x==12
Printf(“I don’t care”);
#else
printf("bye\n"); // this isn't compiled
#endif
#if x==-1
#error “x value is invalid
#endif
int main(void) {
int i = 10, j= 20;
printf("%d\n", *ptr);
/*
Error as ptr is declared as constant
ptr = &j;
printf("%d\n", *ptr);*/
return 0;
}
ptr = &j;
printf("%d\n", *ptr);
return 0;
}
#402.
/* constant pointer to a constant integer */
const int * const ptr = &i;