Академический Документы
Профессиональный Документы
Культура Документы
int *ptr;
(a)ptr is a integer variable
(b)ptr is a pointer to an integer quantity
(c)Invalid statement
(d)None of these
[Q002] Several declarations involving pointers are shown below. Pick the correct solution.
int *ptr[10];
(a)ptr is a pointer to an integer quantity
(b)ptr is a pointer to a 10-element integer array
(c)ptr is a 10-element array of pointers to integer quantities
(d)None of these
[Q003] Several declarations involving pointers are shown below. Pick the correct solution.
int (*ptr)[10];
(a)ptr is a pointer to an integer quantity
(b)ptr is a pointer to a 10-element integer array
(c)ptr is a 10-element array of pointers to integer quantities
(d)None of these
[Q004] Several declarations involving pointers are shown below. Pick the correct solution.
int *ptr(void);
(a)ptr is a pointer to an integer
(b)ptr is a function that returns a pointer to an integer quantity
(c)ptr is a function pointer that returns integer quantity
(d)None of these
[Q005] Several declarations involving pointers are shown below. Pick the correct solution.
int ptr(int *a);
(a)Invalid statement
(b)ptr is a function that accepts an argument which is a pointer to a integer returns an integer
quantity
(c)ptr is a function pointer
(d)None of these
[Q006] Several declarations involving pointers are shown below. Pick the correct
solution.
int *ptr(int *a);
(a)Invalid statement
(b)ptr is a function pointer that accepts an argument which is a pointer to a integer returns
an integer quantity
(c)ptr is a function that accepts an argument which is a pointer to a integer returns a pointer to an
integer quantity
(d)None of these
[Q007] Several declarations involving pointers are shown below. Pick the correct solution.
int (*ptr)(char *a);
(a)Invalid statement
(b)ptr is a pointer to a function that accepts an argument which is a pointer to a character returns
an integer quantity
(c)ptr is a function that accepts an argument which is a pointer to a character returns a
pointer to an integer quantity
(d)None of these
[Q008] Several declarations involving pointers are shown below. Pick the correct solution.
int (*ptr(int *b))[5];
(a)Invalid statement
(b)ptr is a pointer to a function that accepts pointer to an integer returns a 5-element
integer array
(c)ptr is a function that accepts an argument which is a pointer to a integer returns a pointer to a 5element integer array
(d)None of these
[Q009] Several declarations involving pointers are shown below. Pick the correct solution.
char ptr(int (*a)[]);
(a)Invalid statement
(b)ptr is a function that accepts an argument which is a pointer to a integer array returns an
character quantity
(c)ptr is a function that accepts an argument which is an array of pointers to integers
returns an character quantity
(d)None of these
[Q010] Several declarations involving pointers are shown below. Pick the correct solution.
char ptr(int *a[]);
(a)Invalid statement
(b)ptr is a function that accepts an argument which is a pointer to a integer array returns
an character quantity
(c)ptr is a function that accepts an argument which is an array of pointers to integers returns an
character quantity
(d)None of these
[Q011] Several declarations involving pointers are shown below. Pick the correct solution.
int *ptr(char a[]);
(a)ptr is a function pointer
(b)ptr is a function that accepts an argument which is a character array returns an integer
(c)ptr is a function that accepts an argument which is a character array returns a pointer to an
integer quantity
(d)None of these
[Q012] Several declarations involving pointers are shown below. Pick the correct solution.
int *ptr(char *a[]);
(a)ptr is a function pointer
(b)ptr is a function that accepts an argument which is a pointer to a character array
[Q013] Several declarations involving pointers are shown below. Pick the correct solution.
int (*ptr)(char (*a)[]);
(a)ptr is a function that accepts an argument which is a pointer to a character array
returns a pointer to an integer quantity
(b)ptr is a pointer to a function that accepts an argument which is a pointer to a character
array returns an integer quantity
(c)ptr is a pointer to a function that accepts an argument which is a array of pointers to
characters returns an integer quantity
(d)None of these
[Q014] Several declarations involving pointers are shown below. Pick the correct solution.
int *(*ptr)(char (*a)[]);
(a)ptr is a function that accepts an argument which is a pointer to a character array
returns a pointer to an integer quantity
(b)ptr is a pointer to a function that accepts an argument which is a pointer to a character array
returns a pointer to an integer quantity
(c)ptr is a pointer to a function that accepts an argument which is a array of pointers to
characters returns a pointer to an integer quantity
(d)None of these
[Q015] Several declarations involving pointers are shown below. Pick the correct solution.
int *(*ptr)(char (*a)[]);
(a)ptr is a function that accepts an argument which is a pointer to a character array
returns a pointer to an integer quantity
(b)ptr is a pointer to a function that accepts an argument which is a pointer to a character
array returns a pointer to an integer quantity
(c)ptr is a pointer to a function that accepts an argument which is an array of pointers to
characters returns a pointer to an integer quantity
(d)None of these
[Q016] Several declarations involving pointers are shown below. Pick the correct solution.
int (*ptr[10])(void);
(a)Invalid statement
(b)ptr is a function that returns an integer quantity
(c)ptr is a 10-element array of pointers to functions. Each function returns an integer quantity.
(d)ptr is pointer to a function that returns a pointer to a 10-element integers
[Q017] Several declarations involving pointers are shown below. Pick the correct solution.
int (*ptr[10])(float a);
(a)Invalid statement
(b)ptr is a function that returns an integer quantity
(c)ptr is a 10-element array of pointers to functions. Each function accepts an argument which is a
float and returns an integer quantity.
(d)ptr is pointer to a function that accepts an argument which is a float and returns a
pointer to a 10-element integers
[Q018] Several declarations involving pointers are shown below. Pick the correct solution.
int *(*ptr[10])(float a);
(a)Invalid statement
(b)ptr is a function that returns an integer quantity
(c)ptr is a 10-element array of pointers to functions. Each function accepts an argument
which is a float and returns an integer quantity.
(d)ptr is a 10-element array of pointers to functions. Each function accepts an argument which is a
float and returns a pointer to an integer quantity.
[Q019] Several declarations involving pointers are shown below. Pick the correct solution.
int *(*ptr[10])(float *a);
(a)Invalid statement
(b)ptr is a function that returns an integer quantity
(c)ptr is a 10-element array of pointers to functions. Each function accepts an argument
which is a pointer to a float and returns an integer quantity.
(d)ptr is a 10-element array of pointers to functions. Each function accepts an argument which is a
pointer to a float and returns a pointer to an integer quantity.
[Q020] Several declarations involving pointers are shown below. Pick the correct solution.
int *ptr(char (*a)[]);
(a)ptr is a function pointer
(b)ptr is a function that accepts an argument which is a pointer to a character array returns a pointer
to an integer quantity
(c)ptr is a function that accepts an argument which is a array of pointers to characters
returns a pointer to an integer quantity
(a)Compile-Time Error (b)555 554 555 (c)556 554 555 (d)557 554 555
{
float val=5.75;
int *ptr=&val;
printf("%.2f %.2f",*(float *)ptr,val);
return(0);
}
(a)Compile-Time Error (b)5.75 5.75 (c)5.00 5.75 (d)None of these
int val=77;
const int const *ptr=&val;
printf("%d",*ptr);
return(0);
}
(a)Compile-Time Error (b)Run-Time Error (c)77 (d)None of these
{
int matrix[2][3]={{1,2,3},{4,5,6}};
printf("%d %d %d\n",*(*(matrix)),*(*(matrix+1)+2),*(*matrix+1));
printf("%d %d %d",*(matrix[0]+2),*(matrix[1]+1),*(*(matrix+1)));
return(0);
}
(a)Compile-Time Error
(b)1 5 2
634
(c)1 6 2
354
(d)1 6 2
345
#include <stdio.h>
2.
int main()
3.
4.
char *p = NULL;
5.
char *q = 0;
6.
if (p)
7.
printf(" p ");
8.
else
9.
printf("nullp");
10.
if (q)
11.
printf("q\n");
12.
else
13.
printf(" nullq\n");
14.
a) nullp nullq
b) Depends on the compiler
c) x nullq where x can be p or nullp depending on the value of NULL
d) p q
#include <stdio.h>
2.
int main()
3.
4.
int i = 10;
5.
void *p = &i;
6.
printf("%d\n", (int)*p);
7.
return 0;
8.
#include <stdio.h>
2.
int main()
3.
4.
int i = 10;
5.
void *p = &i;
6.
printf("%f\n", *(float*)p);
7.
return 0;
8.
#include <stdio.h>
2.
int *f();
3.
int main()
4.
5.
int *p = f();
6.
printf("%d\n", *p);
7.
8.
int *f()
9.
10.
int *j = (int*)malloc(sizeof(int));
11.
*j = 10;
12.
return j;
13.
a) 10
b) Compile time error
c) Segmentation fault/runtime crash since pointer to local variable is returned
d) Undefined behaviour
#include <stdio.h>
2.
int *f();
3.
int main()
4.
5.
int *p = f();
6.
printf("%d\n", *p);
7.
8.
int *f()
9.
10.
int j = 10;
11.
return &j;
12.
a) 10
b) Compile time error
c) Segmentation fault/runtime crash
d) Undefined behaviour
6. Comment on the following pointer declaration?
int *ptr, p;
a) ptr is a pointer to integer, p is not
b) ptr and p, both are pointers to integer
c) ptr is a pointer to integer, p may or may not be
d) ptr and p both are not pointers to integer
7. What is the output of this C code?
1.
#include <stdio.h>
2.
int main()
3.
4.
5.
ptr = &a;
6.
*ptr += 1;
7.
8.
a) 10,10
b) 10,11
c) 11,10
d) 11,11
8. Comment on the following?
const int *ptr;
a) You cannot change the value pointed by ptr
b) You cannot change the pointer ptr itself
c) Both (a) and (b)
d) You can change the pointer as well as the value pointed by it
#include <stdio.h>
2.
int x = 0;
3.
void main()
4.
5.
6.
printf("%p\n", ptr);
7.
x++;
8.
9.
#include <stdio.h>
2.
int x = 0;
3.
void main()
4.
5.
6.
printf("%p\n", ptr);
7.
ptr++;
8.
9.
#include <stdio.h>
2.
void main()
3.
4.
int x = 0;
5.
6.
printf("%p\n", ptr);
7.
ptr++;
8.
9.
#include <stdio.h>
2.
void main()
3.
4.
int x = 0;
5.
6.
printf("%p\n", ptr);
7.
#include <stdio.h>
2.
void main()
3.
4.
int x = 0;
5.
6.
printf("%d\n", *ptr);
7.
4. The maximum number of arguments that can be passed in a single function are_____________
a) 127 b) 253 c) 361 d) No limits in number of arguments
5. What is the output of this C code?
1.
#include <stdio.h>
2.
3.
4.
5.
6.
void main()
7.
8.
int a = 6, b = 5;
9.
m(&a, &b);
10.
11.
a) 5 6 b) 6 5 c) 5 5 d) 6 6
6. What is the output of this C code?
1.
#include <stdio.h>
2.
3.
4.
int i = 0;
5.
6.
printf("%d\t", p[i]);
7.
8.
void main()
9.
10.
11.
m(&a);
12.
#include <stdio.h>
2.
3.
4.
int temp = p;
5.
p = q;
6.
q = temp;
7.
8.
void main()
9.
10.
int a = 6, b = 5;
11.
m(a, b);
12.
13.
a) 5 6 b) 5 5 c) 6 5 d) 6 6
8. What is the output of this C code?
1.
#include <stdio.h>
2.
3.
4.
5.
6.
void main()
7.
8.
int a = 6, b = 5;
9.
m(a);
10.
#include <stdio.h>
2.
void m(int p)
3.
4.
printf("%d\n", p);
5.
6.
void main()
7.
8.
int a = 6, b = 5;
9.
m(a, b);
10.
11.
#include <stdio.h>
2.
void foo(int*);
3.
int main()
4.
5.
int i = 10;
6.
foo((&i)++);
7.
8.
9.
10.
printf("%d\n", *p);
11.
a) 10
b) Some garbage value
c) Compile time error
d) Segmentation fault/code crash
Answer:c
2. What is the output of this C code?
1.
#include <stdio.h>
2.
void foo(int*);
3.
int main()
4.
5.
6.
foo(p++);
7.
8.
9.
10.
printf("%d\n", *p);
11.
a) 10
b) Some garbage value
c) Compile time error
d) Segmentation fault
Answer:a
3. What is the output of this C code?
1.
#include <stdio.h>
2.
3.
int main()
4.
5.
6.
foo(&i);
7.
8.
9.
10.
printf("%f\n", *p);
11.
a) 10.000000
b) 0.000000
c) Compile time error
d) Undefined behaviour
Answer:b
4. What is the output of this C code?
1.
#include <stdio.h>
2.
int main()
3.
4.
5.
foo(&i);
6.
7.
8.
9.
10.
int j = 2;
11.
p = &j;
12.
13.
a) 2 97
b) 2 2
c) Compile time error
d) Segmentation fault/code crash
Answer:a
5. What is the output of this C code?
1.
#include <stdio.h>
2.
int main()
3.
4.
5.
foo(&p);
6.
7.
return 0;
8.
9.
10.
11.
int j = 2;
12.
*p = &j;
13.
14.
a) 2 2
b) 2 97
c) Undefined behaviour
d) Segmentation fault/code crash
Answer:a
#include <stdio.h>
2.
int main()
3.
4.
int i = 11;
5.
int *p = &i;
6.
foo(&p);
7.
8.
9.
10.
11.
int j = 10;
12.
*p = &j;
13.
14.
1.
#include <stdio.h>
2.
int main()
3.
4.
int i = 10;
5.
int *p = &i;
6.
foo(&p);
7.
8.
9.
10.
11.
12.
int j = 11;
13.
*p = &j;
14.
15.
a) 11 11 11
b) 11 11 Undefined-value
c) Compile time error
d) Segmentation fault/code-crash
Answer:b
8. What is the output of the code below?
1.
#include <stdio.h>
2.
int main()
3.
4.
int i = 10;
5.
6.
foo(&p);
7.
printf("%d\n", *p);
8.
9.
10.
11.
int j = 11;
12.
*p = &j;
13.
printf("%d\n", **p);
14.
a) 11 11
b) Undefined behaviour
#include <stdio.h>
2.
void main()
3.
4.
5.
int *p = a;
6.
printf("%p\t%p", p, a);
7.
#include <stdio.h>
2.
void main()
3.
4.
char *s = "hello";
5.
char *p = s;
6.
printf("%p\t%p", p, s);
7.
#include <stdio.h>
2.
void main()
3.
4.
5.
char *p = s;
6.
7.
#include <stdio.h>
2.
void main()
3.
4.
5.
char *p = s;
6.
7.
a) h e
b) l l
c) l o
d) l e
View Answer
Answer:d
s[1]);
#include <stdio.h>
2.
void main()
3.
4.
5.
char *p = s;
6.
7.
a) h h
b) Run time error
c) l l
d) e e
View Answer
Answer:d
6. What is the output of the code given below?
1.
#include <stdio.h>
2.
3.
int main()
4.
5.
6.
foo(ary);
7.
8.
9.
10.
11.
int i = 10;
12.
p = &i;
13.
14.
a) 10 10
b) Compile time error
c) 10 1
d) Undefined behaviour
View Answer
Answer:c
#include <stdio.h>
2.
int main()
3.
4.
5.
int *p = ary + 3;
6.
printf("%d\n", p[-2]);
7.
a) 1
b) 2
c) Compile time error
d) Some garbage value
View Answer
Answer:b
8. What is the output of the code given below?
1.
#include <stdio.h>
2.
int main()
3.
4.
5.
int *p = ary + 3;
6.
7.
a) 2 3
b) Compile time error
c) 2 4
d) 2 somegarbagevalue
View Answer
Answer:d
Here is a listing of C questions and puzzles on Address Arithmetic along with answers, explanations and/or
solutions:
1. What is the output of this C code?
1.
#include <stdio.h>
2.
int main()
3.
4.
5.
ptr = ptr + 2;
6.
printf("%u", ptr);
7.
a) 102
b) 104
c) 108
d) 116
View Answer
Answer:d
2. Comment on the output of this C code?
1.
#include <stdio.h>
2.
int main()
3.
4.
5.
6.
printf("%d", p + q);
7.
a) 2
b) 3
c) 5
d) Compile time error
View Answer
Answer:d
3. Which of the following operand can be applied to pointers p and q?
(Assuming initialization as int *a = (int *)2; int *b = (int *)3;)
a) a + b
b) a b
c) a * b
d) a / b
View Answer
Answer:b
4. What is the size of *ptr in a 32-bit machine, (assuming initialization as int *ptr = 10;)?
a) 1
b) 2
c) 4
d) 8
View Answer
Answer:c
5. Which of following logical operation can be applied to pointers?
(Assuming initialization int *a = 2; int *b = 3;)
a) a | b
b) a ^ b
c) a & b
d) None of the mentioned
View Answer
Answer:d
6. What is the output of this C code?
1.
#include <stdio.h>
2.
void main()
3.
4.
char *s = "hello";
5.
char *p = s;
6.
7.
a) h e
b) e l
c) h h
d) e e
View Answer
Answer:d
7. What is the output of this C code?
1.
#include <stdio.h>
2.
void main()
3.
4.
char *s = "hello";
5.
char *p = s;
6.
7.
a) e h
b) Compile time error
c) h h
d) h e
View Answer
Answer:d
8. What is the output of this C code?
1.
#include <stdio.h>
2.
void main()
3.
4.
char *s = "hello";
5.
char *n = "cjn";
6.
char *p = s + n;
7.
8.
a) h e
b) Compile time error
c) c o
d) h n
View Answer
Answer:b
Here is a listing of online C quiz on Pointers and Arrays along with answers, explanations and/or solutions:
1. What is the output of this C code?
1.
#include <stdio.h>
2.
int main()
3.
4.
5.
printf("%d\n", *ary);
6.
a) 1
b) Compile time error
c) Some garbage value
d) Undefined variable
View Answer
Answer:a
#include <stdio.h>
2.
int main()
3.
4.
5.
int *p;
6.
p = ary + 3;
7.
*p = 5;
8.
printf("%d\n", ary[3]);
9.
a) 4
b) 5
c) Compile time error
d) 3
View Answer
Answer:b
3. Different ways to initialize an array with all elements as zero are
a) int array[5] = {};
b) int array[5] = {0};
c) int a = 0, b = 0, c = 0;
int array[5] = {a, b, c};
d) All of the mentioned
View Answer
Answer:d
4. The elements in the array of the following code are
int array[5] = {5};
a) 5, 5, 5, 5, 5
b) 5, 0, 0, 0, 0
c) 5, (garbage), (garbage), (garbage), (garbage)
d) (garbage), (garbage), (garbage), (garbage), 5
View Answer
Answer:b
5. Which of the following declaration is illegal?
a) int a = 0, b = 1, c = 2;
int array[3] = {a, b, c};
b) int size = 3;
int array[size];
c) int size = 3;
int array[size] = {1, 2, 3};
#include <stdio.h>
2.
int main()
3.
4.
5.
int p[4];
6.
p = ary;
7.
printf("%d\n", p[1]);
8.
a) 1
b) Compile time error
c) Undefined behaviour
d) 2
View Answer
Answer:b
Address Arithmetic
1. What is the output of this C code?
1.
#include <stdio.h>
2.
int main()
3.
4.
5.
ptr = ptr + 2;
6.
printf("%u", ptr);
7.
a) 102
b) 104
c) 108
d) 116
View Answer
Answer:d
2. Comment on the output of this C code?
1.
#include <stdio.h>
2.
int main()
3.
4.
5.
6.
printf("%d", p + q);
7.
a) 2
b) 3
c) 5
d) Compile time error
View Answer
Answer:d
3. Which of the following operand can be applied to pointers p and q?
(Assuming initialization as int *a = (int *)2; int *b = (int *)3;)
a) a + b
b) a b
c) a * b
d) a / b
View Answer
Answer:b
4. What is the size of *ptr in a 32-bit machine, (assuming initialization as int *ptr = 10;)?
a) 1
b) 2
c) 4
d) 8
View Answer
Answer:c
5. Which of following logical operation can be applied to pointers?
(Assuming initialization int *a = 2; int *b = 3;)
a) a | b
b) a ^ b
c) a & b
d) None of the mentioned
View Answer
Answer:d
6. What is the output of this C code?
1.
#include <stdio.h>
2.
void main()
3.
4.
char *s = "hello";
5.
char *p = s;
6.
7.
a) h e
b) e l
c) h h
d) e e
View Answer
Answer:d
7. What is the output of this C code?
1.
#include <stdio.h>
2.
void main()
3.
4.
char *s = "hello";
5.
char *p = s;
6.
7.
a) e h
b) Compile time error
c) h h
d) h e
View Answer
Answer:d
8. What is the output of this C code?
1.
#include <stdio.h>
2.
void main()
3.
4.
char *s = "hello";
5.
char *n = "cjn";
6.
char *p = s + n;
7.
8.
a) h e
b) Compile time error
c) c o
d) h n
View Answer
Answer:b
#include <stdio.h>
2.
void main()
3.
4.
char *s = "hello";
5.
char *p = s * 3;
6.
7.
a) h e
b) l e
c) Compile time error
d) l h
View Answer
#include <stdio.h>
2.
void main()
3.
4.
5.
char *p = s + 2;
6.
7.
a) l e
b) h e
c) l l
d) h l
View Answer
3. What is the output of this C code?
1.
#include <stdio.h>
2.
int main()
3.
4.
void *p;
5.
6.
p = &a[3];
7.
8.
int n = p - ptr;
9.
printf("%d\n", n);
10.
a) 1
b) Compile time error
c) Segmentation fault
d) 4
View Answer
4. What is the output of this C code?
1.
#include <stdio.h>
2.
int main()
3.
4.
void *p;
5.
6.
p = &a[3];
7.
8.
9.
printf("%d\n", n);
10.
a) 1
b) Compile time error
c) Segmentation fault
d) 4
View Answer
5. What is the output of this C code?
1.
#include <stdio.h>
2.
int main()
3.
4.
5.
6.
7.
printf("%d\n", n);
8.
a) -3
b) 5
c) 4
d) Compile time error
View Answer
6. What is the output of this C code?
1.
#include <stdio.h>
2.
int main()
3.
4.
5.
int *p = &a[1];
6.
7.
ptr = ptr * 1;
8.
printf("%d\n", *ptr);
9.
a) 2
b) 1
c) Compile time error
d) Undefined behaviour
View Answer
7. What is the output of this C code?
1.
#include <stdio.h>
2.
int main()
3.
4.
5.
int *ptr
6.
float n = 1;
7.
ptr = ptr + n;
8.
printf("%d\n", *ptr);
9.
&a[2];
a) 4
b) 3
c) Compile time error
d) Undefined behaviour
View Answer
8. What is the output of this C code?
1.
#include <stdio.h>
2.
int main()
3.
4.
5.
void *p = &a[1];
6.
7.
int n = 1;
8.
n = ptr - p;
9.
printf("%d\n", n);
10.
a) 1
b) 4
c) Compile time error
#include <stdio.h>
2.
int main()
3.
4.
5.
6.
strcpy(strc, str);
7.
printf("%s\n", strc);
8.
return 0;
9.
a) hello, world
b) Crash/segmentation fault
c) Undefined behaviour
d) Run time error
2. What is the output of this C code?
1.
#include <stdio.h>
2.
int main()
3.
4.
5.
6.
strcpy(strc, str);
7.
printf("%s\n", strc);
8.
return 0;
9.
a) hello world
b) hello worldg india
c) Compile time error
d) Undefined behaviour
1.
#include <stdio.h>
2.
int main()
3.
4.
5.
6.
strcpy(strc, str);
7.
printf("%s\n", strc);
8.
return 0;
9.
a) hello, world!!
b) Compile time error
c) Undefined behaviour
d) Segmenation fault
#include <stdio.h>
2.
int main()
3.
4.
5.
str[5] = '.';
6.
printf("%s\n", str);
7.
return 0;
8.
a) hello. world
b) hello, world
c) Compile error
d) Segmentation fault
5. What is the output of this C code?
1.
#include <stdio.h>
2.
int main()
3.
4.
5.
str[5] = '.';
6.
printf("%s\n", str);
7.
return 0;
8.
a) hello. world
b) hello, world
c) Compile error
d) Segmentation fault
#include <stdio.h>
2.
int main()
3.
4.
5.
6.
7.
return 0;
8.
a) 11 11
b) 12 12
c) 4 12
d) 4 11
#include <stdio.h>
2.
int main()
3.
4.
5.
6.
7.
return 0;
8.
a) 11 11
b) 12 11
c) 11 12
d) x 11 where x can be any positive integer.
#include <stdio.h>
2.
3.
4.
k++;
5.
k[2] = 'm';
6.
printf("%c\n", *k);
7.
8.
void main()
9.
10.
11.
f(s);
12.
a) l
b) e
c) h
d) o
#include <stdio.h>
2.
3.
4.
printf("%s", k);
5.
6.
void main()
7.
8.
9.
fun(s);
10.
a) hello
b) Run time error
c) Nothing
d) h
1.
#include <stdio.h>
2.
int main()
3.
4.
5.
6.
7.
8.
View Answer
Answer:b
4. Comment on the output of this C code?
1.
#include <stdio.h>
2.
3.
4.
return a + b;
5.
6.
int main()
7.
8.
9.
fn_ptr = add;
10.
11.
#include <stdio.h>
2.
3.
4.
k++;
5.
k[2] = 'm';
6.
7.
void main()
8.
9.
10.
f(s);
11.
printf("%c\n", *s);
12.
a) h
b) e
c) m
d) o;
View Answer
Answer:a
8.What is the output of this C code?
1.
#include <stdio.h>
2.
void main()
3.
4.
5.
s++;
6.
printf("%c\n", *s);
7.
Pointers to Pointers
1. What is the output of this C code?
1.
#include <stdio.h>
2.
void main()
3.
4.
int k = 5;
5.
int *p = &k;
6.
int **m
7.
8.
a) 5 5 5
b) 5 5 junk value
= &p;
c) 5 junk junk
d) Run time error
View Answer
Answer:a
2. What is the output of this C code?
1.
#include <stdio.h>
2.
void main()
3.
4.
int k = 5;
5.
int *p = &k;
6.
int **m
7.
8.
= &p;
a) 5 5 5
b) 5 5 junk value
c) 5 junk junk
d) Compile time error
View Answer
Answer:d
3. What is the output of this C code?
1.
#include <stdio.h>
2.
void main()
3.
4.
int k = 5;
5.
int *p = &k;
6.
int **m
7.
**m = 6;
8.
printf("%d\n", k);
9.
= &p;
a) 5
b) Compile time error
c) 6
d) Junk
View Answer
Answer:c
#include <stdio.h>
2.
void main()
3.
4.
5.
int *p = a;
6.
int *r = &p;
7.
printf("%d", (**r));
8.
a) 1
b) Compile time error
c) Address of a
d) Junk value
View Answer
Answer:b
5. What is the output of this C code?
1.
#include <stdio.h>
2.
void main()
3.
4.
5.
int *p = a;
6.
7.
8.
Answer:d
7. What is the output of this C code?
1.
#include <stdio.h>
2.
int main()
3.
4.
int a = 1, b = 2, c = 3;
5.
6.
7.
*sptr = ptr2;
8.
a) ptr1 points to a
b) ptr1 points to b
c) sptr points to ptr2
d) None of the mentioned
View Answer
Answer:b
8. What is the output of this C code?
1.
#include <stdio.h>
2.
void main()
3.
4.
5.
int *p = a;
6.
7.
8.
1. What substitution should be made to //-Ref such that ptr1 points to variable C?
1.
#include <stdio.h>
2.
int main()
3.
4.
int a = 1, b = 2, c = 3;
5.
6.
7.
//-Ref
8.
a) *sptr = &c;
b) **sptr = &c;
c) *ptr1 = &c;
d) None of the mentioned.
View Answer
Answer:a
2. Which of the following declaration throw run-time error?
a) int **c = &c;
b) int **c = &*c;
c) int **c = **c;
d) None of the mentioned
View Answer
Answer:d
3. Comment on the output of this C code?
1.
#include <stdio.h>
2.
int main()
3.
4.
int a = 10;
5.
6.
1.
#include <stdio.h>
2.
void main()
3.
4.
int k = 5;
5.
int *p = &k;
6.
int **m
7.
8.
= &p;
a) 5 5 5
b) 5 5 junk value
c) 5 junk junk
d) Compile time error
View Answer
Answer:a
5. What is the output of this C code?
1.
#include <stdio.h>
2.
void main()
3.
4.
int k = 5;
5.
int *p = &k;
6.
int **m
7.
8.
= &p;
a) 5 5 5
b) 5 5 junk value
c) 5 junk junk
d) Compile time error
View Answer
Answer:d
6. What is the output of this C code?
1.
#include <stdio.h>
2.
void main()
3.
4.
int k = 5;
5.
int *p = &k;
6.
int **m
7.
**m = 6;
8.
printf("%d\n", k);
9.
= &p;
a) 5
b) Run time error
c) 6
d) Junk
View Answer
Answer:c
7. What is the output of this C code?
1.
#include <stdio.h>
2.
void main()
3.
4.
5.
int *p = a;
6.
int *r = &p;
7.
printf("%d", (**r));
8.
a) 1
b) Compile time error
c) Address of a
d) Junk value
View Answer
Answer:b
Multidimensional Arrays
1. What is the output of this C code?
1.
#include <stdio.h>
2.
void main()
3.
4.
5.
int i = 0, j = 0;
6.
7.
8.
printf("%d", a[i][j]);
9.
a) 1 2 3 4 5 0
b) 1 2 3 4 5 junk
c) 1 2 3 4 5 5
d) Run time error
View Answer
Answer:a
2. What is the output of this C code?
1.
#include <stdio.h>
2.
void main()
3.
4.
5.
int i = 0, j = 0;
6.
7.
8.
printf("%d", a[i][j]);
9.
a) 1 2 3 junk 4 5
b) Compile time error
c) 1 2 3 0 4 5
d) 1 2 3 3 4 5
View Answer
Answer:b
3. What is the output of this C code?
1.
#include <stdio.h>
2.
3.
4.
a[0][1] = 3;
5.
int i = 0, j = 0;
6.
7.
8.
printf("%d", a[i][j]);
9.
10.
void main()
11.
12.
13.
f(a);
14.
a) 0 3 0 0 0 0
b) Junk 3 junk junk junk junk
c) Compile time error
d) All junk values
View Answer
Answer:a
4. What is the output of this C code?
1.
#include <stdio.h>
2.
3.
4.
a[0][1] = 3;
5.
int i = 0, j = 0;
6.
7.
8.
printf("%d", a[i][j]);
9.
10.
void main()
11.
12.
13.
f(a);
14.
a) 0 3 0 0 0 0
b) Junk 3 junk junk junk junk
c) Compile time error
d) All junk values
View Answer
Answer:c
5. What is the output of this C code?
1.
#include <stdio.h>
2.
3.
4.
a[0][1] = 3;
5.
int i = 0, j = 0;
6.
7.
8.
printf("%d", a[i][j]);
9.
10.
void main()
11.
12.
13.
f(a);
14.
a) 0 3 0 0 0 0
b) Junk 3 junk junk junk junk
c) Compile time error
d) All junk values
View Answer
Answer:c
6. Comment on the following statement:
int (*a)[7];
a) An array a of pointers.
b) A pointer a to an array.
c) A ragged array.
d) None of the mentioned
View Answer
Answer:b
7. Comment on the 2 arrays regarding P and Q:
int *a1[8];
int *(a3[8]);
P. Array of pointers
Q. Pointer to an array
a) a1 is P, a2 is Q
b) a1 is P, a2 is P
c) a1 is Q, a2 is P
d) a1 is Q, a2 is Q
View Answer
Answer:b
8. Which of the following is not possible statically in C?
a) Jagged Array
b) Rectangular Array
c) Cuboidal Array
d) Multidimensional Array
View Answer
Answer:a
Here is a listing of C multiple choice questions on Multidimensional Arrays along with answers,
explanations and/or solutions:
1. What is the correct syntax to send a 3-dimensional array as a parameter?
(Assuming declaration int a[5][4][3];)
a) func(a);
b) func(&a);
c) func(*a);
d) func(**a);
View Answer
Answer:a
2. Applications of multidimensional array are?
a) Matrix-Multiplication
b) Minimum Spanning Tree
c) Finding connectivity between nodes
d) All of the mentioned
View Answer
Answer:d
3. What is the output of this C code?
1.
#include <stdio.h>
2.
int main()
3.
4.
int ary[2][3];
5.
foo(ary);
6.
7.
8.
9.
int i = 10, j = 2, k;
10.
ary[0] = &i;
11.
ary[1] = &j;
12.
*ary[0] = 2;
13.
14.
printf("%d\n", *ary[k]);
15.
a) 2 2
b) Compile time error
c) Undefined behaviour
d) 10 2
View Answer
Answer:a
4. What is the output of this C code?
1.
#include <stdio.h>
2.
int main()
3.
4.
int ary[2][3];
5.
foo(ary);
6.
7.
8.
9.
int i = 10, j = 2, k;
10.
ary[0] = &i;
11.
ary[1] = &j;
12.
13.
printf("%d\n", *ary[k]);
14.
#include <stdio.h>
2.
int main()
3.
4.
foo(ary);
5.
6.
7.
8.
9.
int *ary[2];
10.
ary[0] = &i;
11.
ary[1] = &j;
12.
printf("%d\n", ary[0][1]);
13.
a) 10
b) 2
c) Compile time error
d) Undefined behaviour
View Answer
Answer:d
6. What is the output of this C code?
1.
#include <stdio.h>
2.
int main()
3.
4.
5.
ary[0][0] = &j;
6.
printf("%d\n", *ary[0][0]);
7.
#include <stdio.h>
2.
int main()
3.
4.
int ary[2][3];
5.
6.
7.
printf("%d\n", ary[1][0]);
}
Here is a listing of C quiz on Initialization of Pointer Arrays along with answers, explanations and/or
solutions:
1. To declare a 3 dimension array using pointers, which of the following is the correct syntax:
a) char *a[][];
b) char **a[];
c) char ***a;
d) All of the mentioned
View Answer
Answer:a
2. Comment on the output of this C code?
1.
#include <stdio.h>
2.
int main()
3.
4.
5.
printf("%s", a);
6.
char *c = World;
char *a[] = {b, c};
d) All of the mentioned.
View Answer
Answer:d
4. What is the output of this C code?
1.
#include <stdio.h>
2.
void main()
3.
4.
5.
int i = 0;
6.
7.
printf("%s", *(a[i]));
8.
a) Segmentation fault
b) hi hello how followed by 7 null values
c) 10 null values
d) depends on compiler
View Answer
Answer:a
5. What is the output of this C code?
1.
#include <stdio.h>
2.
void main()
3.
4.
5.
int i = 0, j = 0;
6.
a[0] = "hey";
7.
8.
printf("%s\n", a[i]);
9.
Answer:c
6. What is the output of this C code?
1.
#include <stdio.h>
2.
void main()
3.
4.
5.
printf("%d\n", sizeof(a));
6.
a) 10
b) 13
c) Run time error
d) 40
View Answer
Answer:d
7. What is the output of this C code?
1.
#include <stdio.h>
2.
void main()
3.
4.
5.
printf("%d\n", sizeof(a[1]));
6.
a) 6
b) 4
c) 5
d) 3
View Answer
Answer:b
8. What is the output of this C code?
1.
#include <stdio.h>
2.
void main()
3.
4.
5.
int i = 0;
6.
7.
printf("%s", a[i]);
8.
#include <stdio.h>
2.
int main()
3.
4.
5.
printf("%s", (p)[0]);
6.
return 0;
7.
#include <stdio.h>
2.
int main()
3.
4.
5.
printf("%s", (p)[0]);
6.
return 0;
7.
d) Address of hello
View Answer
Answer:b
3. What is the output of this C code?
1.
#include <stdio.h>
2.
int main()
3.
4.
int i = 0, j = 1;
5.
6.
printf("%d", (*a)[0]);
7.
return 0;
8.
#include <stdio.h>
2.
int main()
3.
4.
int i = 0, j = 1;
5.
6.
printf("%d", *a[0]);
7.
return 0;
8.
1.
#include <stdio.h>
2.
int main()
3.
4.
int i = 0, j = 1;
5.
6.
printf("%d", (*a)[1]);
7.
return 0;
8.
Here is a listing of C programming questions on Pointers Vs. Multi-dimensional Arrays along with answers,
explanations and/or solutions:
1. int a[10][20]; which is true for a
a) a is true two-dimensional array
b) 200 int-sized locations have been set aside
c) The conventional rectangular subscript calculation 20 * row + col is used to find the element
a[row, col]
#include <stdio.h>
2.
void main()
3.
4.
5.
printf("%s", a[2]);
6.
a) fellows
b) fellow
c) fello
d) fell
View Answer
Answer:c
4. What is the output of this C code?
1.
#include <stdio.h>
2.
void main()
3.
4.
5.
printf("%p\n", a);
6.
printf("%p", a[0]);
7.
d) hi hello fello
View Answer
Answer:a
5. What is the output of this C code?
1.
#include <stdio.h>
2.
void main()
3.
4.
5.
printf("%d", sizeof(a[1]));
6.
a) 2
b) 4
c) 5
d) 10
View Answer
Answer:c
6. What is the output of the code given below?
1.
#include <stdio.h>
2.
int main()
3.
4.
5.
printf("%s", a[0]);
6.
return 0;
7.
#include <stdio.h>
2.
int main()
3.
4.
5.
printf("%s", a[0]);
6.
return 0;
7.
Here is a listing of C interview questions on Command Line Arguments along with answers, explanations
and/or solutions:
1. What does argv and argc indicate in command-line arguments?
(Assuming: int main(int argc, char *argv[]) )
a) argument count, argument variable
b) argument count, argument vector
c) argument control, argument variable
d) argument control, argument vector
View Answer
Answer:b
2. Which of the following syntax is correct for command-line arguments?
a) int main(int var, char *varg[])
b) int main(char *argv[], int argc)
c) int main()
{
int argv, char *argc[];
}
#include <stdio.h>
2.
3.
4.
printf("%d\n", argc);
5.
return 0;
6.
a) 0
b) 1
c) Depends on the platform
d) Depends on the compiler
View Answer
Answer:b
4. What is the output of this C code (run without any commandline arguments)?
1.
#include <stdio.h>
2.
3.
4.
while (argc--)
5.
printf("%s\n", argv[argc]);
6.
return 0;
7.
#include <stdio.h>
2.
3.
4.
printf("%s\n", argv[argc]);
5.
return 0;
6.
#include <stdio.h>
2.
3.
4.
5.
printf("%s\n", *argv);
6.
return 0;
7.
#include <stdio.h>
2.
3.
4.
while (*argv
5.
printf("%s\n", *(argv++));
6.
return 0;
7.
!=
NULL)
#include <stdio.h>
2.
3.
4.
5.
printf("%s\n",
6.
return 0;
7.
*(argv++));
Here is a listing of C quiz on Pointer to Functions along with answers, explanations and/or solutions:
#include <stdio.h>
2.
void first()
3.
4.
printf("first");
5.
6.
void second()
7.
8.
first();
9.
10.
void third()
11.
12.
second();
13.
14.
void main()
15.
16.
void (*ptr)();
17.
ptr = third;
18.
ptr();
19.
a) Function first
b) Function second
c) Function third
d) None of the mentioned
View Answer
Answer:d
2. How to call a function without using the function name to send parameters?
a) typedefs
b) Function pointer
c) Both (a) and (b)
d) None of the mentioned
View Answer
Answer:b
3. Correct syntax to pass a Function Pointer as an argument
a) void pass(int (*fptr)(int, float, char)){}
b) void pass(*fptr(int, float, char)){}
c) void pass(int (*fptr)){}
d) void pass(*fptr){}
View Answer
Answer:a
4. Which of the following is not possible in C?
a) Array of function pointer
b) Returning a function pointer
c) Comparison of function pointer
d) None of the mentioned
View Answer
Answer:d
5. What is the output of this C code?
1.
#include <stdio.h>
2.
void first()
3.
4.
printf("Hello World");
5.
6.
void main()
7.
8.
9.
ptr++
10.
ptr();
11.
#include <stdio.h>
2.
3.
4.
return a * b * c;
5.
6.
void main()
7.
8.
9.
function_pointer
mul;
10.
11.
function_pointer(2, 3, 4));
12.
#include <stdio.h>
2.
3.
4.
return a * b * c;
5.
6.
void main()
7.
8.
9.
function_pointer = mul;
10.
11.
function_pointer(2, 3, 4));
12.
#include <stdio.h>
2.
3.
int myfoo(int);
4.
int (*fooptr)(int);
5.
int ((*foo(int)))(int);
6.
int main()
7.
8.
fooptr = foo(0);
9.
fooptr(10);
10.
11.
12.
13.
return myfoo;
14.
15.
int myfoo(int i)
16.
17.
printf("%d\n", i + 1);
18.
a) 10
b) 11
c) Compile time error
d) Undefined behaviour
View Answer
Answer:b
#include <stdio.h>
2.
3.
4.
return a * b * c;
5.
6.
void main()
7.
8.
int *function_pointer;
9.
function_pointer = mul;
10.
11.
function_pointer(2, 3, 4));
12.
d) Varies
View Answer
Answer:b
2. What is the output of this C code?
1.
#include <stdio.h>
2.
3.
4.
return a - b - c;
5.
6.
void main()
7.
8.
9.
function_pointer = ⊂
10.
11.
(*function_pointer)(2, 3, 4));
12.
#include <stdio.h>
2.
void f(int);
3.
void (*foo)() = f;
4.
5.
6.
foo(10);
7.
return 0;
8.
9.
void f(int i)
10.
11.
printf("%d\n", i);
12.
#include <stdio.h>
2.
void f(int);
3.
void (*foo)(void) = f;
4.
5.
6.
foo(10);
7.
return 0;
8.
9.
void f(int i)
10.
11.
12.
printf("%d\n", i);
}
#include <stdio.h>
2.
void f(int);
3.
void (*foo)(float) = f;
4.
int main()
5.
6.
foo(10);
7.
8.
void f(int i)
9.
10.
printf("%d\n", i);
11.
#include <stdio.h>
2.
3.
4.
5.
int main()
6.
7.
f(foo(10));
8.
9.
10.
11.
i(11);
12.
13.
int myfoo(int i)
14.
15.
printf("%d\n", i);
16.
return i;
17.
Answer:d
8. What is the output of this C code?
1.
#include <stdio.h>
2.
3.
int myfoo(int);
4.
5.
int main()
6.
7.
f(foo);
8.
9.
void f(int(*i)(int ))
10.
11.
i(11);
12.
13.
int myfoo(int i)
14.
15.
printf("%d\n", i);
16.
return i;
17.
a) 10 11
b) 11
c) 10
d) Undefined behaviour
View Answer
Answer:b
Here is a listing of C question bank on Complicated Declarations along with answers, explanations and/or
solutions:
1. What is the output of this C code?
1.
#include <stdio.h>
2.
void main()
3.
4.
struct student
5.
6.
int no;
7.
char name[20];
8.
};
9.
struct student s;
10.
no = 8;
11.
printf("%d", no);
12.
a) Nothing
b) Compile time error
c) Junk
d) 8
View Answer
Answer:b
2. What is the output of this C code?
1.
#include <stdio.h>
2.
struct student
3.
4.
int no;
5.
char name[20];
6.
};
7.
void main()
8.
9.
struct student s;
10.
s.no = 8;
11.
printf("hello");
12.
#include <stdio.h>
2.
struct student
3.
4.
int no = 5;
5.
char name[20];
6.
};
7.
void main()
8.
9.
struct student s;
10.
s.no = 8;
11.
printf("hello");
12.
a) Nothing
b) Compile time error
c) hello
d) Varies
View Answer
Answer:b
4. What is the output of this C code?
1.
#include <stdio.h>
2.
struct student
3.
4.
int no;
5.
char name[20];
6.
};
7.
void main()
8.
9.
student s;
10.
s.name = "hello";
11.
printf("hello");
12.
a) Nothing
b) hello
c) Compile time error
d) Varies
View Answer
Answer:c
5. What is the output of this C code?
1.
#include <stdio.h>
2.
void main()
3.
4.
struct student
5.
6.
int no;
7.
char name[20];
8.
};
9.
struct student s;
10.
s.no = 8;
11.
printf("%s", s.name);
12.
a) Nothing
b) Compile time error
c) Junk
d) 8
View Answer
Answer:c
6. What is the output of this C code?
1.
#include <stdio.h>
2.
struct student
3.
4.
int no;
5.
char name[20];
6.
};
7.
struct student s;
8.
void main()
9.
10.
s.no = 8;
11.
printf("%s", s.name);
12.
a) Nothing
b) Compile time error
c) Junk
d) 8
View Answer
Answer:a
#include <stdio.h>
2.
int main()
3.
4.
int *((*x)())[2];
5.
x();
6.
printf("after x\n");
7.
8.
int *((*x)())[2]
9.
10.
int **str;
11.
12.
return str;
13.
#include <stdio.h>
2.
3.
4.
5.
6.
int main()
7.
8.
y = x();
9.
y(1, 2);
10.
11.
12.
13.
return foo;
14.
15.
16.
17.
18.
a) 1 2.000000
b) 1 2
c) Compile time error
d) Segmentation fault/code crash
View Answer
Answer:a
9. What does this declaration say?
int (*(*y)())[2];
a) y is pointer to the function which returns pointer to integer array
b) y is pointer to the function which returns array of pointers
c) y is function which returns function pointer which in turn returns pointer to integer array
d) y is function which returns array of integers
View Answer
Answer:a
10. What is the output of this C code?
1.
#include <stdio.h>
2.
3.
4.
5.
int main()
6.
7.
x = f;
8.
x();
9.
10.
11.
12.
return foo;
13.
14.
15.
16.
17.
c) 1 2.000000
d) Nothing
View Answer
Answer:a
11. What is the output of this C code?
1.
#include <stdio.h>
2.
3.
4.
5.
int main()
6.
7.
x p = f;
8.
p();
9.
10.
11.
12.
return foo;
13.
14.
15.
16.
17.
Here is a listing of C multiple choice questions on Complicated Declarations along with answers,
explanations and/or solutions:
1. Read the following expression?
void (*ptr)(int);
a) ptr is pointer to int that converts its type to void
b) ptr is pointer to function passing int returning void
1.
#include <stdio.h>
2.
struct student
3.
4.
int no;
5.
char name[20];
6.
7.
void main()
8.
9.
struct student s;
10.
s.no = 8;
11.
printf("hello");
12.
#include <stdio.h>
2.
struct student
3.
4.
int no = 5;
5.
char name[20];
6.
};
7.
void main()
8.
9.
struct student s;
10.
s.no = 8;
11.
printf("hello");
12.
a) Nothing
b) Compile time error
c) hello
d) Varies
View Answer
Answer:b
#include <stdio.h>
2.
struct student
3.
4.
int no;
5.
char name[20];
6.
};
7.
void main()
8.
9.
student s;
10.
s.no = 8;
11.
printf("hello");
12.
a) Nothing
b) hello
c) Compile time error
d) Varies
View Answer
Answer:c
9. What is the output of this C code?
1.
#include <stdio.h>
2.
void main()
3.
4.
struct student
5.
6.
int no;
7.
char name[20];
8.
};
9.
struct student s;
10.
s.no = 8;
11.
printf("%d", s.no);
12.
a) Nothing
b) Compile time error
c) Junk
d) 8
View Answer
Answer:d
10. Is the below declaration legal?
int* ((*x)())[2];
a) true
b) false
c) Undefined behaviour
d) Depends on the standard
View Answer
Answer:b
Here is a listing of C question bank on Complicated Declarations along with answers, explanations and/or
solutions:
1. What is the output of this C code?
1.
#include <stdio.h>
2.
void main()
3.
4.
struct student
5.
6.
int no;
7.
char name[20];
8.
};
9.
struct student s;
10.
no = 8;
11.
printf("%d", no);
12.
a) Nothing
b) Compile time error
c) Junk
d) 8
View Answer
Answer:b
2. What is the output of this C code?
1.
#include <stdio.h>
2.
struct student
3.
4.
int no;
5.
char name[20];
6.
};
7.
void main()
8.
9.
struct student s;
10.
s.no = 8;
11.
printf("hello");
12.
#include <stdio.h>
2.
struct student
3.
4.
int no = 5;
5.
char name[20];
6.
};
7.
void main()
8.
9.
struct student s;
10.
s.no = 8;
11.
printf("hello");
12.
a) Nothing
b) Compile time error
c) hello
d) Varies
View Answer
Answer:b
#include <stdio.h>
2.
struct student
3.
4.
int no;
5.
char name[20];
6.
};
7.
void main()
8.
9.
student s;
10.
s.name = "hello";
11.
printf("hello");
12.
a) Nothing
b) hello
c) Compile time error
d) Varies
View Answer
Answer:c
5. What is the output of this C code?
1.
#include <stdio.h>
2.
void main()
3.
4.
struct student
5.
6.
int no;
7.
char name[20];
8.
};
9.
struct student s;
10.
s.no = 8;
11.
printf("%s", s.name);
12.
a) Nothing
b) Compile time error
c) Junk
d) 8
View Answer
Answer:c
6. What is the output of this C code?
1.
#include <stdio.h>
2.
struct student
3.
4.
int no;
5.
char name[20];
6.
};
7.
struct student s;
8.
void main()
9.
10.
s.no = 8;
11.
printf("%s", s.name);
12.
a) Nothing
b) Compile time error
c) Junk
d) 8
View Answer
Answer:a
7. What is the output of this C code?
1.
#include <stdio.h>
2.
int main()
3.
4.
int *((*x)())[2];
5.
x();
6.
printf("after x\n");
7.
8.
int *((*x)())[2]
9.
10.
int **str;
11.
12.
return str;
13.
#include <stdio.h>
2.
3.
4.
5.
6.
int main()
7.
8.
y = x();
9.
y(1, 2);
10.
11.
12.
13.
return foo;
14.
15.
16.
17.
18.
a) 1 2.000000
b) 1 2
c) Compile time error
d) Segmentation fault/code crash
View Answer
Answer:a
9. What does this declaration say?
int (*(*y)())[2];
a) y is pointer to the function which returns pointer to integer array
b) y is pointer to the function which returns array of pointers
c) y is function which returns function pointer which in turn returns pointer to integer array
#include <stdio.h>
2.
3.
4.
5.
int main()
6.
7.
x = f;
8.
x();
9.
10.
11.
12.
return foo;
13.
14.
15.
16.
17.
#include <stdio.h>
2.
3.
4.
5.
int main()
6.
7.
x p = f;
8.
p();
9.
10.
11.
12.
return foo;
13.
14.
15.
16.
17.
Here is a listing of C multiple choice questions on Complicated Declarations along with answers,
explanations and/or solutions:
1. Read the following expression?
void (*ptr)(int);
a) ptr is pointer to int that converts its type to void
b) ptr is pointer to function passing int returning void
c) ptr is pointer to void that converts its type to int
d) ptr is pointer to function passing void returning int
View Answer
Answer:b
2. Which of the following expression is true for the following?
ptr is array with 3 elements of pointer to function returning pointer of int
a) int **ptr[3]();
b) int *(*ptr[3])();
c) int (*(*ptr[3])());
d) None of the mentioned
View Answer
Answer:b
3. What do the following declaration denote?
int **ptr;
a) ptr is a function pointer that returns pointer to int type
#include <stdio.h>
2.
struct student
3.
4.
int no;
5.
char name[20];
6.
7.
void main()
8.
9.
struct student s;
10.
s.no = 8;
11.
printf("hello");
12.
d) Varies
View Answer
Answer:a
7. What is the output of this C code?
1.
#include <stdio.h>
2.
struct student
3.
4.
int no = 5;
5.
char name[20];
6.
};
7.
void main()
8.
9.
struct student s;
10.
s.no = 8;
11.
printf("hello");
12.
a) Nothing
b) Compile time error
c) hello
d) Varies
View Answer
Answer:b
8. What is the output of this C code?
1.
#include <stdio.h>
2.
struct student
3.
4.
int no;
5.
char name[20];
6.
};
7.
void main()
8.
9.
student s;
10.
s.no = 8;
11.
printf("hello");
12.
a) Nothing
b) hello
c) Compile time error
d) Varies
View Answer
Answer:c
9. What is the output of this C code?
1.
#include <stdio.h>
2.
void main()
3.
4.
struct student
5.
6.
int no;
7.
char name[20];
8.
};
9.
struct student s;
10.
s.no = 8;
11.
printf("%d", s.no);
12.
a) Nothing
b) Compile time error
c) Junk
d) 8
View Answer
Answer:d
10. Is the below declaration legal?
int* ((*x)())[2];
a) true
b) false
c) Undefined behaviour
d) Depends on the standard
View Answer
Answer:b
float f;
}var;
int main()
{
var.i=5;
var.f=9.76723;
printf("%d %.2f",var.i,var.f);
return(0);
}
(a)Compile-Time Error
(b)5 9.76723
(c)5 9.76
(d)5 9.77
(a)1234 1234
(b)1235 1235
(c)1234 1235
(d)1235 1234
(b)55 67.05
(c)555 67.06
(d)555 67.05
(b)7 999.99
(c)5 999.99
(d)None of these
(b)32760 12345.12
A4
1 -5
(c)32760 12345.13
a -5
0.00 65531
(d)32760 12345.13
a5
0.00 65530
int main()
{
printf("%d %d %d\n",var.i,vptr->i,(*vptr).i);
printf("%d %d %d %d %d
%d",var.val[4],*(var.val+4),vptr->val[4],*(vptr-
>val+4),(*vptr).val[4],*((*vptr).val+4));
return(0);
}
(d)None of these
temp tmp=*ptr;
printf("%d %.2f\n",tmp.i,tmp.f);
tmp.i=x;
tmp.f=y;
return tmp;
}
int main()
{
temp a={65535,777.777};
a=alter(&a,-1,666.666);
printf("%d %.2f",a.i,a.f);
return(0);
}
(a)Compile-Time error
(b)65535 777.777
-1 666.666
(c)65535 777.78
-1 666.67
(d)-1 777.78
-1 666.67
(a)Compile-Time Error
(b)Run-Time Error
(c)65872143
(d)56781243
temp->next=list;
list=temp;
while (temp != NULL)
{
printf("%s",temp->str);
temp=temp->next;
}
return(0);
}
(a)Compile-Time Error
(b)HaiFriends
(c)FriendsHai
(d)None of these
int a;
struct B *nextB;
};
(iv) struct B {
int b;
struct B {
int b;
struct B *nextB;
}tempB;
struct B *nextB;
}tempB;
(a) (iv) Only
(b) (iii) Only
(c)All of the these
(d)None of these
Size=4 bytes
(d)None of these
[Q018] What are the largest values that can be assigned to each of the bit fields defined in
[Q017] above.
(a)a=0 b=2 c=3 d=4
(b)a=1 b=2 c=7 d=15
(c)a=1 b=3 c=7 d=15
(d)None of these
unsigned c:10;
}v={1,10000,15,555};
printf("%d %d %d %d",v.i,v.a,v.b,v.c);
printf("\nSize=%d bytes",sizeof v);
return(0);
}
(a)Compile-Time Error
(b)1 10000 15 555
Size=4 bytes
(c)10000 1 15 555
Size=4 bytes
(d)10000 1 15 555
Size=5 bytes
[Q001]
Ans. (d) Though both <struct type name> and <structure variables> are optional, one of
the two must appear. In the above program, <structure variable> i.e. var is used. (2
decimal places or) 2-digit precision of 9.76723 is 9.77
[Q002]
Ans. (d) Both <struct type name> and <structure variables> are optional. Thus the
structure defined in the above program has no use and program executes in the normal
way.
[Q003]
Ans. (c) The members of a structure variable can be assigned initial values in much the
same manner as the elements of an array. The initial values must appear in order in which
they will be assigned to their corresponding strucutre members, enclosed in braces and
separated by commas.
[Q004]
Ans. (c) In the above program, values is the user-defined structure type or the new userdefined data type. Structure variables can then be defined in terms of the n ew data type.
[Q005]
Ans. (a) C language does not permit the initialization of individual structure members
within the template. The initialization must be done only in the declaration of the actual
variables. The correct way to initialize the values is shown in [Q003] or [Q004].
[Q006]
Ans. (d) Illustrating 3 different ways of declaring the structres : first, second and third are
the user-defined structure type. s1, s2 and s3 are structure variables. Also an expression of
the form ++variable.member is equivalent to ++(variable.member), i.e. ++ operator will
apply to the structure member, not the entire structure variable.
[Q007]
Ans. (b) Since value of the member 'i' can be accessed using var.i, vptr->i and
(*vptr).i Similarly 5th value of the member 'val' can be accessed using var.val[4],
*(var.val+4), vptr->val[4], *(vptr->val+4), (*vptr).val[4] and *((*vptr).val+4)
[Q008]
Ans. (c) This program illustrates the transfer of a structure to a function by passing the
structure's address (a pointer) to the function.
[Q009]
Ans. (b) This program illustrates the transfer of a structure to a function by value. Also the
altered structure is now returned directly to the calling portion of the program.
[Q010]
Ans. (d) This program illustrates the transfer of a structure to a function by passing the
structure's address (a pointer) to the function. Also the altered structure is now returned
directly to the calling portion of the program.
[Q011]
Ans. (c) This program illustrates the implementation of a nested structure i.e. structure
inside another structure.
[Q012]
Ans. (d) An entire structure variable can be assigned to another structure variable,
provided both variables have the same composition.
[Q013]
Ans. (c) It is sometimes desirable to include within a structure one member i.e. a pointer
to the parent structure type. Such structures are known as Self-Referencial structures.
These structures are very useful in applications that involve linked data structures, such as
lists and trees. [A linked data structure is not confined to some maximum number of
components. Rather, the data structure can expand or contract in size as required.]
[Q014]
Ans. (d) Since all the above structure declarations are valid in C.
[Q015]
Ans. (c) The above program produces erroneous output (which is machine dependent). In
effect, a union creates a storage location that can be used by any one of its members at a
time. When a different member is assigned a new value, the new value supercedes the
previous member's value. [NOTE : The compiler allocates a piece of storage that is large
enough to hold the largest variable type in the union i.e. all members share the same
address.]
[Q016]
Ans. (b) Since int (2 bytes) + float (4 bytes) = (6 bytes) + Largest among union is int (2
bytes) is equal to (8 bytes). Also the total number of bytes the array 'temp2' requires :
(8 bytes) * (5 bytes) = (40 bytes).
[Q017]
Ans. (b) The four fields within 'v' require a total of 10 bits and these bits can be
accomodated within the first word(16 bits). Unnamed fields can be used to control the
alignment of bit fields within a word of memory. Such fields provide padding within the
word. [NOTE : Some compilers order bit-fields from righ-to-left (i.e. from lower-order bits
to high- order bits) within a word, whereas other compilers order the fields from left-to-
[Q018]
Ans. (c)a=1 (1 bit: 0 or 1)
b=3 (2 bits: 00 or 01 or 10 or 11),
c=7 (3 bits: 000 or 001 or 010 or 011 or 100 or 101 or 110 or 111)
d=15 (4 bits: 0000 or 0001 or 0010 or 0011 or 0100 or 0101 or 0110 or 0111 or 1000
or
1001 or 1010 or 1011 or 1100 or 1101 or 1110 or 1111)
[Q019]
Ans. (a) Since we cannot take the address of a bit field variable i.e. Use of pointer to access
the bit fields is prohibited. Also we cannot use 'scanf' function to read values into a bit field
as it requires the address of a bit field variable. Also array of bit-fields are not permitted
and a function cannot return a bit field.
[Q020]
Ans. (d) Here the bit field variable 'a' will be in first byte of one word, the variable 'i' will be
in the second word and the bit fields 'b' and 'c' will be in the third word. The variables 'a',
'b' and 'c' would not get packed into the same word. [NOTE: one word=2 bytes]