C Programming Language Questions
C Programming Language Questions
Overview Of C
Basic Structure of C Programming
Keywords in C
Identifiers in C
Format Specifiers
Format Specifiers Examples etc
Data Types in C Language
Introduction to Data Types in C
int Data Type in C
float Data Type in C
double Data Type in C
char Data Type in C etc
Variable in C Language
Variable Introduction in C
Variable Declaration and Initialization
Variable types and Scope in C
Local Variable in C
Static Variable in C
Global variables in C
Storage Class in C etc
Constant in C Language
Constants in C ,etc
Operators and Enums in C Language
Introduction to Operator
Arithmetic Operators in C
Relational Operators in C
Bit-wise Operators in C
Logical Operators in C
Assignment Operators in C
Conditional Operator in C
sizeof() Operator in C
Operator Precedence. etc
Decision Making of C Language
Decision Making in C Introduction
if Statement
if-else Statement
Nested if Statement
if else if Ladder
switch case. etc
Loop control in C Language
Loop Introduction in C
while loop in C
do while Loop In C
for Loop in C ,etc
Control Flow in C Programming
break Statement in C
continue Statement in C
go to Statement in C .etc
Array in C Language
Single Dimensional Array
Multi-Dimensional Array in C .etc
String & String functions in C
All String Functions
strcat() function
strncat() function
strcpy() function
strncpy() function
strlen() function
strcmp() function.etc
Function in C Language
Function in C
Function Calling in C
return type in Function
Call by Value in C
User Define Function
Predefined Functions. etc
Recursion in c
Introduction to Recursion
Direct and Indirect Recursion, etc
Pointer in C Language
Pointer in C
types of pointer
NULL pointer
Pointer and Array
Strings as pointers
Pointer to Function.etc
Structure in C Language
Structure in C
Nested Structure in C
Array of Structures in C
Pointer to Structure
Structure to Function in C
typedef in C, etc
Union in C Language Dynamic Memory Allocation
Union in C
C Precedence Table
*= /= %= Right to Left
= \= Right to Left
C Programming Page 1
Q3. Consider the following C program.
#include<stdio.h>
int main()
{
void sum=10;
printf("%v", sum);
return 0;
}
What will be the output of above code?
(a)1
(b)2
(c)10
(d)Compilation Error
C Programming Page 2
Q5. What is the output of the following C code?
#include <stdio.h>
extern int a, b;
extern int c;
extern float f;
int main () {
int a, b;
int c;
float f;
a = 5;
b = 15;
c = a + b;
printf("value of c : %d \n", c);
f = 80/2.0;
printf("value of f : %f \n", f);
return 0;
}
(a) (b) (c) (d) None of these.
20 20.0 20.000000
40.000000 40.0 40.000000
C Programming Page 3
Q6. What is the output of the following code?
#include <stdio.h>
int main(void) {
int a=10;
if (a){
a+=5;
int a=20;
a+=10;
printf("%d ", a);}
printf("%d ", a);
return 0;}
(a)10 30
(b)30 20
(c)30 30
(d)30 15
C Programming Page 4
Q8. Consider the following C code:
#include <stdio.h>
void main()
{
unsigned short var='B';
var+=2;
var++;
printf("var : %c , %d ", var,var);
}
What will be the output of above code:
(a) var : B , 66
(b) var : E , 69
(c) var : E , 68
(d)None of these
C Programming Page 5
Q10. What will be the output of the following code? ______
#include<stdio.h>
int main()
{
int a;
a = (1, 2, 3);
printf("%d", a);
return 0;
}
What will be the output of above code:
(a)1 (b)2 (c)3 (d)Compilation Error.
Q11. Consider the following C code:
#include<stdio.h>
int main()
{
unsigned int num = -5;
printf("%d", ~num);
return 0;
}
What will be the output of above code:
(a)5 (b)4 (c)Compilation Error (d)Some Garbage Value.
Q12. What will be the output of the C program?
#include<stdio.h>
int main()
{
int a = 4, b = 5, c = 3;
printf("a|b&c = %d\n", a|b&c);
return 0;
}
(a)4 (b)5 (c)6 (d)7
C Programming Page 6
Q13. What will be the output of the C program?
#include <stdio.h>
int main()
{
int x = 5;
int y = 11;
int z = 0;
z = x & y;
printf("AND - Value of z is %d\n", z );
z = x | y;
printf("OR - Value of z is %d\n", z );
z = x ^ y;
printf("Exclusive-OR - Value of z is %d\n", z );
getch();
}
(a) AND - Value of z is 1
OR - Value of z is 15
Exclusive-OR - Value of z is 14
(b)
AND - Value of z is 1
OR - Value of z is 5
Exclusive-OR - Value of z is 15
(c) AND - Value of z is 5
OR - Value of z is 5
Exclusive-OR - Value of z is 14
(d) Compilation Error
C Programming Page 7
Q14. What will be the output of the C program?_____
#include <stdio.h>
int main() {
int a = 10;
int c = 0;
c = a << 2;
c = a >> 1;
printf("Value of c is %d\n", c );
return 0;
}
Q15. What is output of following program?
#include<stdio.h>
int main()
{
int m=1, n=2;
for(int j=1;j<=2;j=j+1)
{
m=m+1;
n=n*j;
printf("%d, %d", m, n);
}
}
(a) 2,2,3,4
(b) 2,23,4
(c) 2234
(d) compile time error
C Programming Page 8
Q16. What is output of following program?
#include <stdio.h>
int main( )
{
int x = 10, y = 2, z;
for(z = 0; z<x; )
z = z++ +y;
printf("%d\n", z) ;
return 0;
}
(a)8
(b) 10
(c)12
(d) compile time error
Q17. What is the output produced by the following code fragment:
#include<stdio.h>
int main(){
int counter;
for ( counter = 0; counter < 5; ++counter )
{
if ( counter < 2 || counter > 3 )
{
printf("yes ");}
else { printf("no ");}
}
}
(a) no yes yes yes no
(b) yes yes yes no no
(c) no no yes yes yes
(d) yes yes no no yes
C Programming Page 9
Q18. What will be printed by the following code? __________
#include<stdio.h>
int main()
{
int i=5,j=5;
while(i+1?--i:j++)
printf("%d", i);
return 0;
}
Q19. What will be the output of following C program?
#include<stdio.h>
int main()
{
int a=25;
return 0;
}
(a)25 26 27
(b)25 26
(c)25 26 27 28
(d) 25
C Programming Page 10
Q20. What will be the output of the C program?
#include<stdio.h>
int main()
{
int a = 1;
while(printf("%d", 4) == 2 == a)
{
printf("Loop Hole ");
}
return 0;
}
(a)Loop Hole
(b)4
(c)1
(d)Infinite loop
Q21. What will be the output of following C program?
#include<stdio.h>
int main()
{
while(!!4)
printf("Hari");
return 0;
}
(a)No Output
(b)Hari Hari Hari Hari
(c)Compilation Error
(d)Infinite Loop
C Programming Page 11
Q22. What will be the output of following C program?
#include<stdio.h>
int main()
{
int a=20;
do
{
printf("%d ", a);
a++;
if(a > 24)
break;
}while(1);
return 0;
}
(a)20 21 22 23
(b)20 21 22 23 24 25
(c) 20 21 22 23 24
(d)20 21 22
C Programming Page 12
Q23. What will be the output of following C program?
#include<stdio.h>
int main()
{
int i[3] = {1, 4, 0};
while(i[1] == i[3])
{
if(i[3])
printf("While Loop ");
else
break;
}
return 0;
}
(a)While Loop (b)0
(c)No output (d)Compilation Error
Q24. What will be the output of following C program?
#include<stdio.h>
int main(){
while(sizeof(0))
{
printf("Loop ");
if(sizeof(0))
break;
else
continue;
}
return 0;
}
(a)4 (b)Loop
(c)Infinite loop (d)No output
C Programming Page 13
Q25. What will be the output of the C program?
#include<stdio.h>
int main()
{
int size = sizeof(volatile) + sizeof(const);
printf("%d",++size);
return 0;
}
(a)8
(b)10
(c)9
(d)Compilation Error
Q26. What will be output when you will execute following c code? ______
#include<stdio.h>
int main(){
int a=3,b=2,c;
a=a==b==0;
switch(1)
{
case 1: a=a+10;
break;
default:
break;
}
c = sizeof(a++);
printf("%d\n", a);
return 0;
}
C Programming Page 14
Q27. What will the following lines of code print?
#include<stdio.h>
#define z 2^5
int main()
{
int students;
students = z*z+z;
printf("%d", students);
return 0;
}
(a) 10 (b) 1056 (c) Compilation error (d) Run time error
Q28. What will be output when you will execute following c code?
#include<stdio.h>
#define label 10
int main(){
int money=10;
switch(money, money*2)
{
case label: printf("first floor");
break;
case label*2:printf("second floor");
break;
case label*3:printf("third floor");
break;
default: printf("ground or top");
case label*4:printf("fourth floor");
break;
}
return 0;
}
(a) first floor (b) second floor (c) third floor (d) None of these
C Programming Page 15
Q29. Consider the following code:
#include <stdio.h>
int main() {
int a[] = {1, 2, 3, 4, 5};
printf("%d", *(++a));
return 0;
}
What will be the output of above code:
(a) 1
(b) 2
(c) Compile-time Error
(d) Run-time Error
C Programming Page 16
Q31. What will be the output of following C program?
#include <stdio.h>
int x=60;
void main()
{
{
auto int x;
{
int x=10;
{
volatile unsigned x=20;
printf("%d\t",x);
}
printf("%d\t",x);
}
printf("%d\t",x);
}
}
(a )Compilation Error (b) 20 10 0
(c) 20 20 10 (d)20 100 100
Q32. What will be the output of the given program?
#include <stdio.h>
int main ()
{
int a[] = {2, 1, 6, 9, 5};
int i, j, m;
i = ++a[1];
j = a[1]++;
m = a[i++];
printf("%d, %d, %d, %d", j, i, m, a[1]);
return 0;
}
(a) 1,2,6,3 (b)2,3,6,3
(c) 1,6,2,3 (d) 2,3,6,3
C Programming Page 17
Q33. Consider the following code:
#include<stdio.h>
int main()
{
int a[10] = {1, 2, 3, [8]=5, 6,};
for(int i = 0; i < 10; i++)
printf("%d", a[i])
return 0;
}
(a) 0000000000 (b) 123000056
(c) 1230000056 (d) Compiler Error
Q34. Consider the following code:. What is the value printed by the below code?_______
# include <stdio.h>
int main()
{
char s1[] = "Hello";
char s2[] = {'H', 'e', 'l', 'l', 'o'};
printf("%ld", sizeof(s1)/sizeof(s1[0]))*(sizeof(s2)/sizeof(s2[0]));
return 0;
}
Q35. Consider the following code (assuming the size of integer as 4 bytes):
#include <stdio.h>
int main()
{
int i = 12;
int j = sizeof(i++);
printf("i: %d j: %d", i, j);
return 0;
}
(a) i: 12 j: 4 (b) i: 13 j: 4
(c) Compile-time Error (d) None of these.
C Programming Page 18
Q36. Consider the following C Code:
#include<stdio.h>
void main()
{
int c=0, d=5,e=10,a;
a=c>1?d>1||e>1?100:200:300;
printf("a=%d", a);
}
What is the output of the above C code?
(a) a=300 (b) a=100 (c) a=200 (d) None of these
Q37. Consider the following C Code:
#include<stdio.h>
int main()
{
int x = 2;
(x & 1) ? printf("true") : printf("false");
return 0;
}
What is the output of the above C code?
(a)true (b)false (c)0 (d)1
Q38. What will be the value of x after executing the program?
#include<stdio.h>
int main ( )
{
int x;
x = printf("India's best institute for Gate CS&IT");
printf("\nx = % d" , x);
return 0;
}
(a) x= 32 (b) x = 37 (c)Garbage value (d) Error
C Programming Page 19
Q39. Find the output for the following C program? _____
int fun ( int n ) {
int x = 1, k ;
if ( n == 1) return x ;
for( k = 1 ; k < n ; ++ k )
x = x + fun( k ) * fun( n - 2 ) ;
return x ;
}
int main()
{ int x;
x=fun(4);
printf("%d", x);
}
Q40. Consider the following code:
#include<stdio.h>
int main()
{
int a[][3] = {1, 2, 3, 4, 5, 6, 7, 8, 9};
printf("Hello");
return 0;
}
(a) Hello (b) Compiler Error (c) Runtime Error (d) None of the above
C Programming Page 20
Q41. What will be the output of following C program?
#include <stdio.h>
int main()
{
int ary[][2][3] =
{
{{1,2,3},{4,5,6}},
{{7,8,9},{10,11,12}}
};
printf("%d %d", ary[0][0][0], ary[1][1][1]);
return 0;
}
(a)1 12 (b)1 10 (c)1 11 (d)4 12
Q42. Consider the following code:
#include <stdio.h>
void fun()
{
int i = 10;
printf(“%d”, i);
}
int main ()
{
fun;
printf(“12”);
return 0;
}
(a) 10 12 (b) 12 (c) Compiler Error (d) 10
C Programming Page 21
Q43. What will be output when you will execute following c code? _______
#include<stdio.h>
int main()
{
int a=3,b=2,c;
a=a==b==0;
switch(1)
{
case 1: a=a+10;
break;
default:
break;
}
c = sizeof(a++);
printf("%d\n", a);
return 0;
}
Q44. [MSQ]
Consider the following pseudo code fragment, where y is an integer that has been
initialized.
int i = 1
int j = 1
while (i < 10)
j=j*i
i=i+1
if (i==y)
break
end if
end while
Which of the following statements is/are TRUE at the end of the while loop? Choose
from the following options.
(a) (i == 10) or (i == y) (b) If y > 10, then i == 10
(c) If j = 6, then y == 4 (d) None of these.
C Programming Page 22
Q45. Consider the following C program, if input to getchar is ‘c’ when what will be the
output of given code.
#include <stdio.h>
int main()
{
char ch;
while(1)
{
ch=getchar();
if(ch=='n')
{
break;
}
printf("hello");
}
return 0;
}
(a)hello (b)no output (c)hellohello (d)infinite loop
Q46. What will be the output of given C code:
#include<stdio.h>
int main(){
int i=1;
for(i=3;i<=10;i++){
if(i==5)
{
continue;
}
printf("%d \t", i);
}
return 0;
}
(a)It will print numbers from 1 to 10
(b)1 2 3 4 5 6 7 8 9 10
(c)3 4 5 6 7 8 9 10
(d)3 4 6 7 8 9 10
C Programming Page 23
Q47. What will be the output of following C program?
#include <stdio.h>
int main()
{
int i, j, k;
{
for(j=0;j<3;j++)
{
for(k=0;k<1;k++)
{
printf("%d %d\n", j, k);
if(j == 2)
{
goto out;
}
}
}
}
out:
printf("came out of the loop");
}
(a) (b) (c) (d)Compilation
00 00 00 Error
10 01 10
20 10 20
came out of the 11
loop 20
21
22
came out of the
loop
C Programming Page 24
Q48. What will be the output of following C program?
#include<stdio.h>
int main()
{
int i = 2, j = 3;
for(--i && j++ ; i<=10; i+=2)
{
printf("loop ");
}
return 0;
}
(a)loop loop loop loop (b) loop loop loop loop loop
(c)Compilation Error (d)Infinite loop
Q49. Consider the following program modifying an n × n square matrix A:
for i = 1 to n:
for j = 1 to n:
temp = A[i][j] + 10
A[i][j] = A[j][i]
A[j][i] = temp - 10
end for
end for
Which of the following statements about the contents of the matrix A at the end of
this program must be TRUE ?
(a) The new A is the transpose of the old A.
(b)All elements above the diagonal have their values increased by 10 and all values
below have their values decreased by 10.
(c) All elements above the diagonal have their values decreased by 10 and all values
below have their values increased by 10.
(d) A remains unchanged
C Programming Page 25
Q50. Consider the following C Code:
#include<stdio.h>
#define SQUARE(X) X * X
void main ( )
{
printf ("\n Square = %d" , SQUARE(10+2) );
return 0;
}
What is the output of the above C code?
(a) Square = 144
(b) Square =32
(c) Square =122
(d) Square =12
Q51. What is sum of the values printed by following program? _________
#include <stdio.h>
void m();
int main()
{m(); m(); return 0;}
void m()
{
static int x = 5;
x++;
printf("%d\n", x);
}
C Programming Page 26
Q52. Consider the following C code:
#include <stdio.h>
int main()
{
static int a = 5;
if(a--)
{
printf("%d", a);
main(a);
}
}
What will be the output of above code.
(a) 43210 (b) 00000 (c) -1-1-1-1-1 (d) 01234
Q53. Consider the following C Code:
#include <stdio.h>
void count(void);
static int countseq = 4;
void main() {
while(countseq--) {
count();
}
return 0;
}
void count( void ) {
static int i = 3;
i++;
printf("i is %d and count is %d\n", i, countseq);
}
C Programming Page 27
What will be the output of above code:
(a) (b) (c) (d)
i is 4 and count is i is 3 and count is i is 4 and count is i is 4 and count is
4 i is 5 and count i 4 i is 2 and count i 3 i is 5 and count i 3 i is 5 and count i
s 5 i is 6 and count s 5 i is 1 and count s 2 i is 6 and count s 2 i is 6 and count
is 6 i is 7 and cou is 6 i is 0 and cou is 1 i is 7 and cou is 1 i is 7 and cou
nt is 7 nt is 7 nt is 0 nt is 0
i is 8 and count is
-1
C Programming Page 28
Q56. Consider the following C code (for 32 bit machine)
#include<stdio.h>
int main()
{
struct node
{
int a; //Assume integer is 4 bytes long
char b; //Assume character is 1 bytes long
double c; //Assume double is 8 bytes long
float d; //Assume float is 4 bytes long
}s;
printf("%d", sizeof(s));
return 0;
}
What is the output of the above code?________
Q57. Consider the following C code:
#include <stdio.h>
struct zeal
{
int x;
int y;
};
void foo(struct zeal*);
int main()
{
struct zeal p1[] = {1, 2, 3, 4};
foo(p1);
}
C Programming Page 29
void foo(struct zeal p[])
{
printf("%d\n", p[1].x);
}
What is the output of the above code?
(a) Compile time error (b) 3 (c) 2 (d) 1
Q58. What will be the output of following C program?
#include<stdio.h>
struct AIR2022
{
char *name;
char street[10];
int pin;
}obj={"INDIGO","SPICE-JET",452009},*p=&obj;
int main()
{
printf("%s %s", p->name,(*p).street);
return 0;
}
(a) Compilation Error (b) INDIGO SPICE-JET
(c)Null Null (d) INDIGO
Q59. Consider the following C code:
#include<stdio.h>
struct classroom
{
int students[7];
};
int main()
C Programming Page 30
{
struct classroom c1 = {1, 3, 5, 7, 9, 11};
int *ptr;
ptr = (int *)&c1;
printf("%d",*(ptr + 4));
return 0;
}
What is the output of the above code?
(a)11 (b)7 (c)9 (d)Compilation Error
Q60. What will be the output of following C program?
#include <stdio.h>
int main()
{
int *ptr;
int a;
ptr = &a;
*ptr = 0;
printf(" a = %d", a);
printf(" *ptr = %d", *ptr);
*ptr += 4;
printf(" a = %d,", a);
printf(" *ptr = %d,", *ptr);
(*ptr)++;
printf(" a = %d,", a);
printf(" *ptr = %d,", *ptr);
C Programming Page 31
return 0;
}
(a) a = 0, *ptr = 0, a = 4 ,*ptr = 4 , a = 5 ,*ptr = 5.
(b) a = garbage value, *ptr = 0, a = garbage value ,*ptr = 4 , a = 5 ,*ptr = 5.
(c) a = 0,*ptr = 0, a = garbage value ,*ptr = 4 , a = 4 ,*ptr = garbage value.
(d) a = 0, *ptr = 0, a = 0 ,*ptr = 0 , a = 0 ,*ptr = 0.
Q61. What will be the output of following C program?
#include <stdio.h>
#include <string.h>
union demo
{
char x;
int i;
float f;
long double y;
};
int main( )
{
union demo d1;
printf( " %d\n", sizeof(d1));
return 0;
}
(a)4
(b)8
(c)16
(d)20
C Programming Page 32
Q62. What will be the output of following C program?
#include "stdio.h"
typedef enum{
Male, Female, Transgender
}Gender;
int main()
{
Gender var =Transgender ;
printf("%d",var);
return 0;
}
(a) Transgender (b)3 (c)2 (d)1
Q63. Consider the following code (Assume size of pointer be 4 bytes):
#include<stdio.h>
int main()
{
int a[] = {1, 2, 3, 4};
int *p = &a+1;
printf("%d", *(p-1));
return 0;
}
(a) 1
(b) 2
(c) 3
(d) 4
C Programming Page 33
Q64. Consider the following code:
#include <stdio.h>
int main()
{
int a[] = {1, 2, 3, 4, 5};
printf("%d", *(a+1));
return 0;
}
What will be the output of the above code.
(a) 1
(b) 2
(c) Compile-time Error
(d) Run-time Error
Q65. Consider the following C Code:
#include <stdio.h>
int main()
{
int *p, x = 20;
p = &x;
*p += 1;
printf("%d, %d\n", *p, x);
}
What is the output of this C code?
(a)20, 20
(b) 20, 21
(c) 21, 20
(d) 21, 21
C Programming Page 34
Q66. Fill the question mark to get "Null pointer" as an output?
#include<stdio.h>
int main(){
char *ptr = "Null pointer";
void *vptr;
vptr = &ptr;
printf ("%s”, ?);
return 0;
}
(a)*(char **)vptr
(b) (char **)vptr
(c) *(char *)vptr
(d) (char *)vptr
Q67. Consider the following C Code:
#include<stdio.h>
int main()
{
int i = 100;
int *p1, *p2;
p1 = &i;
p2 = ++p1;
--p1;
printf("diff : %u\n", p2-p1);
return 0;
}
What is the output of above C code?
(a) diff : 0
(b) diff :1
(c) diff : 2
(d) Garbage value
C Programming Page 35
Q68. What will be output of following program?
#include<stdio.h>
int main() {
int a = 10;
void *p = &a;
sizeof(a++);
int *ptr = p;
printf("%u",*ptr);
return 0;
}
(a) 10
(b) 11
(c) Address of a
(d) Compilation Error
Q69. Consider the following C Code:
#include <stdio.h>
void main()
{
int i = 2;
int a[5] = {10,20,30,40,50};
int *ptr1;
int *ptr2;
ptr2 = &i;
ptr1 = a;
printf("%u\n", *(ptr1-- + (*ptr2)--) + ++*ptr2 + 2);
}
What is the output of above C code?___________
C Programming Page 36
Q70. Consider the following code:
#include<stdio.h>
int main()
{
void *a[10];
printf("Hello");
return 0;
}
(a) Hello
(b) Compiler Error
(c) Runtime Error
(d) None of the above
Q71. What will be the output of following C program?
Add a statement in the function fun () such that address of a get stored in X.
main()
{
int *X;
void fun(int**)
fun(&X);
}
void fun(int**Y)
{
int a = 20;
/* Add Statement */
}
(a)X=&a
(b) *Y=&a
(c) *x=&a
(d) Y=&a
C Programming Page 37
Q72. What will be the output of following C program?
#include<stdio.h>
void function(char**);
int main()
{
char *arr[] = { "ADA", "CN", "DBMS", "DISCRETE", "ALGEBRA" };
function(arr);
return 0;
}
void function(char **ptr)
{
char *ptr1;
ptr1 = (ptr += sizeof(int))[-2];
printf("%s\n", ptr1);
}
(a)ADA (b)DBMS (c) TOC (d) ALGEBRA
Q73. What will be the output of following program?
#include <stdio.h>
int main()
{
int arr[]={10,11,12,13,14,16,18};
int *ptr, ZONE;
//initialize ptr
ptr = arr;
//printing the elements
for(ZONE=2; ZONE<8; ZONE++)
printf("arr[%d]: %d\n",ZONE,*(ptr+ZONE));
return 0;
}
C Programming Page 38
a) b) c) d)
arr[0]: 10 arr[2]: 12 arr[0]: 11 arr[2]: 10
arr[1]: 11 arr[3]: 13 arr[1]: 12 arr[3]: 12
arr[2]: 12 arr[4]: 14 arr[2]: 13 arr[4]: 13
arr[3]: 13 arr[5]: 16 arr[3]: 14 arr[5]: 14
arr[4]: 14 arr[6]: 18 arr[4]: 15 arr[6]: 11
arr[5]:15 arr[7]:0 arr[7]:0
arr[6]:16
}
(a) Compilation Error (b)G
(c)A (d)I
Q75. What will be the output of following program?
#include<stdio.h>
int main()
{
int x[6]={10,20,30,40,50,60};
int *ptr =x;
printf("%u\n",*ptr +3 );
printf("%u\n",*(ptr +2) +5 );
printf("%u\n",*(ptr +3)- 10 );
printf("%o\n",0123 );
return 0;
}
C Programming Page 39
a) Compilation b) 13 c) 10 d)13
Error 35 20 25
30 30 40
123 40 0123
C Programming Page 40
Q78. What will be the output of following program?
#include<stdio.h>
void fun(int *a, int *b)
{
++b; a[2] = a[1] + 6;
}
int main()
{
char A[5] = {'0','1','7','3','4'};
fun(A, A[2]);
printf("%d", A[2]);
return 0;
}
(a) Compilation Error (b) 55 (c)7 (d)1
Q79. Consider the following C Code:
#include <stdio.h>
void main()
{
int i = 5;
int *j = &i;
int **k = &j;
printf("%d, %d, %d\n", i, ++*j, *k++);
}
What is the output of above C code?
C Programming Page 41
Q80. What will be the output of following C program?
#include <stdio.h>
int main ()
{
int xyz[] = { 23, 90,91 };
int *xyz_ptr = &xyz;
printf("%i\n", xyz_ptr[1]);
return 0;
}
(a)91 (b) 90 (c)23 (d) Compilation Error
Q81. Consider the following C Code:
#include<stdio.h>
int main()
{
char
*s[]={"sunday","monday","tuesday","wednesday","thursday","friday","saturday"};
char **ptr[] = {s+3, s+2, s+1, s, s+6, s+5, s+4};
char ***p;
p = ptr;
p+1;
printf("%c", *(*(*++p+1))+3);
printf("%c", *(*(s+2)+2));
printf("%c", *(*(*ptr+3)+1));
printf("%c", *(*(s+1))-1);
return 0;
}
What is the output of above C code?
(a) zeal (b) weal (c) zeel (d) None of these
C Programming Page 42
Q82. Consider the following C Code:
#include<stdio.h>
int main()
{
short a[3][2]={3,6,9,12,15,18};
printf("%d %d",*(a+1)[1],**(a+2));
return 0;
}
What is the output of above C code?
(a) 15, 9 (b) 15, 15 (c) 9, 15 (d) 6, 18
Q83. #include <stdio.h>
int main()
{
int a[5] = {1,2,3,4,5};
int *ptr = (int*)(&a+1);
printf("%d %d", *(a+1), *(ptr-1));
return 0;
}
(a) 2 5 (b) Garbage Value (c) Compiler Error (d) Segmentation Fault
Q84. What is the output of the following c code:
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
int i;
int *ptr = (int *) malloc(5 * sizeof(int));
for (i=0; i<5; i++)
C Programming Page 43
*(ptr + i) = i;
Q85. In the context of the below program snippet, pick the best answer.
#include<stdio.h>
int arr[10][10][10];
int main()
{
arr[5][5][5] = 123;
printf("%d",arr[5][5][5]); // 1
printf("%d",*(*(*(arr+5)+5)+5)); // 2
printf("%d",(*(*(arr+5)+5))[5]); // 3
printf("%d",*((*(arr+5))[5]+5)); // 4
return 0;
}
Which of the given printf statement(s) would be able to print arr[5][5][5]?
(a)Both (1) and (2) would compile and both would print 123.
(b) Only (1), (2) and (3) would compile and all three would print 123.
(c) All (1), (2), (3) and (4) would compile but only (1) and (2) would print 123.
(d) All (1), (2), (3) and (4) would compile and all would print 123.
C Programming Page 44
Q86. Which of the following defines a variable ‘a’ as an array of pointers to integers?
(a) int *b[10], a[10]; (b) int *b, a[10];
(c) int b, *a[10]; (d) int b, (*a)[10];
Q87. What will be output of following program?
#include<stdio.h>
int main()
{
static char *s[] = {"black", "white", "pink", "violet"};
char **ptr[] = {s+3, s+2, s+1, s}, ***p;
p = ptr;
p++;
printf("%s", *(*p+1));
return 0;
}
(a) ink (b) violet (c) black (d) compilation error
Q88. What would be the last value printed by this program? ________
#include <stdio.h>
int x = 10;
int main()
{
int *ptr;
ptr = &x;
printf(" x = %d\n", x);
*ptr *= 5;
printf(" x = %d\n", x);
(*ptr)++;
printf(" x = %d\n", x);
return 0;
}
C Programming Page 45
Q89. What is the output of the following program?
#include <stdio.h>
int main()
{
int arr[] = {1, 2, 3, 8, 9};
int *p = arr+4;
--*p;
p -= 2;
printf("%d", *p+1);
return 0;
}
(a) 8 (b) 9 (c) 4 (d) None of these
Q90. Consider the following code:
#include<stdio.h>
int main()
{
int a[][3] = {1, 2, 3, 4, 5, 6, 7, 8, 9};
printf("%d", *(a[1]+0));
return 0;
}
(a) 1 (b) 4 (c) 2 (d) 5
Q91. Consider the following C Code:
#include <stdio.h>
void main()
{
int a[5] = {10,20,30,40,50};
int *ptr;
ptr = a;
C Programming Page 46
printf("%u ", *++ptr + 3);
printf("%u ", *(ptr--+ 2) + 5);
printf("%u ", *(ptr+3)-10);
}
What is the output of above C code?
(a) 23, 35, 30 (b) 14, 45, 30 (c) 23, 45, 30 (d) 14, 35, 30
Q92. Consider the following C Code:
#include<stdio.h>
int main()
{
int a[5][2] = {{1, 2},{3, 4},{5, 6},{7, 8},{9, 10}};
int i, j;
for(j=0; j<=4; j++)
printf("%d ",*(*(a)+j));
}
What is the output of above C code?
(a) 1, 3, 5, 7, 9 (b) 2, 4, 6, 8, 10
(c) 1, 2, 3, 4, 5 (d) 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
Q93. What will be the output of following program?
#include <stdio.h>
int main(void)
{
int x[2 ][3]={1,2,3,4,5,6};
printf("%d",*(*(1+x)+1));
return 0;
}
(a)5 (b)6 (c)7 (d)8
C Programming Page 47
Q94. Consider the following C Code:
#include<stdio.h>
#include<string.h>
void main()
{
char p[20];
char *s = "GATEATZEAL";
int l = strlen(s);
int i;
for (i = 0; i<=l; i++)
p[i] = *(s + --l - i);
printf("%s", p);
}
What is the output of above C code?
(a) LEAZTAETAG (b) LETEA (c) AZATG (d) None of these
Q95. What is the output of above C code?
#include<stdio.h>
#include<string.h>
int main()
{
char *str = "abc";
int i;
for(i = 0; i < strlen(str); i++)
printf("%s", str++);
return 0;
}
(a)abcbc (b)bcabc (c)abc (d)cba
C Programming Page 48
Q96. Consider the following C Code:
#include <stdio.h>
int main()
{
int x;
x = 0;
do {
printf( "Hello world!\n" );
} while ( x != 0 );
}
What is the output of above C code?
(a)Hello world (b)No output
(c)Compilation Error (d)Run time Error.
Q97. Consider the following C Code:
#include<stdio.h>
int main()
{
/* assume array begins at location 1002
and the size of integer is 2 bytes */
int a[][4] = {1,2,3,4,5,6,7,8,9,10,11,12};
printf("%u, %u, %u", a[0]+ 1,*( a[0]+ 1),*(*(a + 0 )+ 1 ));
return 0;
}
What is the output of above C code?
(a) 2, 2, 2 (b)Garbage value, 2, 2 (c) 1004, 2, 2 (d)None of these
C Programming Page 49
Q98. What is the output of the following program ?
#include <stdio.h>
int a = 200;
int main()
{
float a=345,b=0,c=24;
float *p=&a;
float **q=&p;
a=200;
printf("%.2f",**(q));
return 0;
}
(a) 200
(b) 200.00
(c) Compiler error
(d) runs time error
Q99. Consider the following C Code:
#include<stdio.h>
int main()
{
/* assume array begins at location 1002
and the size of integer is 2 bytes*/
int a[3][2][4]={{1,2,3,4,5,6,7,8},{9,1,1,2,2,1,4,7},{6,7,8,9,0,0,0,0}};
printf("%d", *(*(*a+2)+1)+3);
return 0;
}
What is the output of above C code?_______
C Programming Page 50
Q100. Consider the following C Code:
#include<stdio.h>
int main()
{
char *s[] = {"Red", "Blue", "Green", "Violet"};
char *ptr[] = {s+3,s+2,s+1,s};
char ***p = ptr;
printf("%s",**++p);
printf("%s", *p[-1]+2);
printf("%s", p[-1][-2]+ 1);
return 0;
}
What is the output of above C code?
(a) Greenletlue
(b) Violetletlue
(c) Greenoletlue
(d) None of these
Q101. What will be the output of following program?
#include <stdio.h>
int main()
{
char a[4] = { 'B', 'C', 'D', 'E' };
char* ppp = &a[0];
*ppp++;
printf("%d ", *++ppp + *ppp);
}
(a)133
(b)131
(c) 130
(d)136
C Programming Page 51
Q102. Consider the following C Code:
#include<stdio.h>
int main()
{
int a[3][2][2] = {1,2,3,4,5,6,7,8,9,10,11,12};
int *ptr1, *ptr2;
ptr1 = &a[2][0][1];
ptr2 = (int*)a;
printf("%d, %d ", *ptr1, *ptr2);
return 0;
}
What is the output of the above C code?
(a) 1, 10 (b) 10, 1 (c) 8, 10 (d) both a and b possible
Q103. Consider the following C Code:
#include<stdio.h>
int main()
{
int a[][2] = {1, 2, 3, 4};
int i, j;
int *p[] = {a, a+1, a+2};
for(i=0; i<2; i++)
for(j=0; j<2; j++)
printf("%d, %d, %d, %d\n", *(*(p+i)+j), *(*(j+p)+i), *(*(i+p)+j), *(*(p+j)+i));
return 0;
}
What is the output of above C code?
C Programming Page 52
1, 1, 1, 1 1, 2, 1, 2 1, 1, 1, 1 1, 2, 3, 4
2, 3, 2, 3 (b) 2, 3, 2, 3 2, 2, 2, 2 2, 3, 4, 1
(a) (c) (d)
3, 2, 3, 2 3, 4, 3, 4 2, 2, 2, 2 3, 4, 1, 2
4, 4, 4, 4 4, 2, 4, 2 3, 3, 3, 3 4, 1, 2, 3
C Programming Page 53
struct p *ptr1 = p1;
int x = (sizeof(p1) / 3);
printf("%d\t", x);
if (x == sizeof(int) + sizeof(char))
printf("%d\n", ptr1->x);
else
printf("false");
}
What is the output of the C code?
(a) Compile time error (b) 8 (c) Undefined behaviour (d)8 false
C Programming Page 54
Q107. Consider the following C Code:
#include<stdio.h>
int main()
{
static int GATE[]={100,200,300,400,500};
static int *p = {GATE+2,GATE,GATE+3,GATE+4,GATE+1};
int **ptr = p;
ptr++;
printf("%d", *ptr);
return 0;
}
What is the output of the above C code?_______
C Programming Page 55
Q109. What will be the output of following C program?
#include <stdio.h>
int main(){
int (*a)[5];
int arr[3][5]={ {10,65,30,40,50},{10,20,30,40,50} };
a = arr;
++a ;
char *ptr = (char*)*a;
++a ;
printf("%d %d %d",**a,*arr[1],*ptr);
return 0;
}
(a)0 10 10
(b)0 30 30
(c)0 40 50
(d)0 10 20
Q110. Consider the following C Code:
#include<stdio.h>
void main()
{
char s[20] = "GATECSIT2019";
char *p = s;
printf("%s", p + *(p+6) - *(p+1));
}
What is the output of above C code?
(a) GATECSIT2019
(b) TECSIT2019
(c) CSIT2019
(d) 2019
C Programming Page 56
Q111. Consider the following C Code:
#include<stdio.h>
int main()
{
int ary[2][2][3] =
{
{{1,2,3},{4,5,6}},
{{7,8,9},{10,11,12}}
};
int *p;
p = &ary;
printf("%d %d",*p, *p+11);
return 0;
}
What is the output of above C code?
(a)2 4 (b)1 11 (c)1 12 (d)2 11
Q112. Consider the following C Code:
#include<stdio.h>
int main()
{
void *p;
char i=74, *j="ZEAL";
int k=65;
p=&i;
printf("%c", *(char*)p);
p=&k;
printf("%c", *(int*)p);
p=j;
printf("%s", (char*)p+2);
return 0;
}
What is the output of the above C code?
(a) ZEAL (b) Z65L (c) ZAAL (d) JAAL
C Programming Page 57