Fundamentals Of Data Structure MCQ'S SET-5
1] What is the output of this C code?
#include
<stdio.h>
void f(char *k)
{
k++;
k[2] = 'm';
}
void main()
{
char s[] =
"hello";
f(s);
printf("%c\n",
*s);
}
ANSWER: A
2] What is the output of this C code?
#include
<stdio.h>
void main()
{
char s[] =
"hello";
s++;
printf("%c\n", *s);
}
ANSWER: A
3] What is the output of this C code?
#include
<stdio.h>
struct student
{
char *c;
};
void main()
{
struct student
m;
struct student
*s = &m;
s->c =
"hello";
printf("%s", s->c);
}
ANSWER: A
4] What is the output of this C code?
#include
<stdio.h>
struct student
{
char *c;
};
void main()
{
struct student
*s;
s->c =
"hello";
printf("%s", s->c);
}
b) Segmentation fault
c) Run time error
d) Nothing
ANSWER: B
5] What is the output of this C code?
#include
<stdio.h>
struct student
{
char *c;
};
void main()
{
struct student
m;
struct student
*s = &m;
s->c =
"hello";
printf("%s", m.c);
}
ANSWER: C
6] What is the output of this C code?
#include
<stdio.h>
struct student
{
char *c;
};
void main()
{
struct student
m;
struct student
*s = &m;
(*s).c =
"hello";
printf("%s", m.c);
}
d) hello
ANSWER: D
7] What is the output of this C code?
#include
<stdio.h>
struct student
{
char *c;
};
void main()
{
struct student
n;
struct student
*s = &n;
(*s).c =
"hello";
printf("%p\n%p\n", s, &n);
}
ANSWER: D
8] What is the output of this C code?
#include
<stdio.h>
struct p
{
int x[2];
};
struct q
{
int *x;
};
int main()
{
struct p p1 =
{1, 2};
struct q
*ptr1;
ptr1->x = (struct q*)&p1.x;
printf("%d\n", ptr1->x[1]);
}
ANSWER: B
9] What is the output of this C code?
#include
<stdio.h>
struct p
{
int x[2];
};
struct q
{
int *x;
};
int main()
{
struct p p1 =
{1, 2};
struct q
*ptr1;
ptr1->x = (struct q*)&p1.x;
printf("%d\n", ptr1->x[1]);
}
ANSWER: B
10] What is the output of this C code?
#include
<stdio.h>
struct p
{
int x;
int y;
};
int main()
{
struct p p1[]
= {1, 2, 3, 4, 5, 6};
struct p *ptr1
= p1;
printf("%d %d\n", ptr1->x, (ptr1 + 2)->x);
}
ANSWER: A
11] What is the output of this C code?
#include
<stdio.h>
struct p
{
int x;
char y;
};
int main(){
struct p p1[] = {1, 92, 3, 94, 5, 96};
struct p *ptr1
= p1;
int x =
(sizeof(p1) / sizeof(struct p));
printf("%d %d\n", ptr1->x, (ptr1 + x - 1)->x);
}
d) 1 5
ANSWER: D
12] What is the output of this C code (considering sizeof char is 1 and pointer is 4)?
#include
<stdio.h>
int main()
{
char *a[2] =
{"hello", "hi"};
printf("%d", sizeof(a));
return 0;
}
ANSWER: A
13] What is the output of this C code?
#include
<stdio.h>
int main()
{
char a[2][6] =
{"hello", "hi"};
printf("%d", sizeof(a));
return 0;
}
ANSWER: B
14] What is the output of this C code?
#include
<stdio.h>
int main()
{
char a[2][6] =
{"hello", "hi"};
printf("%d", sizeof(a));
return 0;
}
ANSWER: C
15] Advantage of a multi-dimension array over pointer array.
a) Pre-defined size.ANSWER: D
16] Which of the following operation is possible using a pointer char?(Assuming declaration char *a;)
a) Input via %sb) Generation of multidimensional array
ANSWER: C
17] Comment on the following two operations?
int *a[] = {{1, 2, 3}, {1, 2, 3, 4}}; //- 1int b[4][4] = {{1, 2, 3}, {1, 2, 3, 4}};//- 2
ANSWER: C
18] Comment on the following two operations?
int *a[] = {{1, 2, 3}, {1, 2, 3, 4}}; //- 1int b[][] = {{1, 2, 3}, {1, 2, 3, 4}}; //- 2
ANSWER: D
19] Comment on the following two operations?
int *a[] = {{1, 2, 3}, {1, 2, 3, 4}}; //- 1int b[][] = {{1, 2, 3}, {1, 2, 3, 4}}; //- 2
d) Neither of them work
ANSWER: B
20] Which of the following syntax is correct for command-line arguments?
a) int main(int var, char *varg[]){
int argv, char *argc[];
}