C Programming - 25 Questions
C Programming - 25 Questions
Assuming that the main memory is byte-addressable and that the array DEVA is
stored starting from memory address 0, the address of DEVA[40][50] is 4050.
Which of the following declaration of a ‘two-dimensional array DEVA in C?
A. char DEVA[100][100];
B. char DEVA[50][100];
C. int DEVA[100][100];
D. int DEVA[100][100];
2. Map the following groups. Group-I (Declaration) and Group-II (Variable type)
Group-I Group-II
A)
#include <stdio.h>
int main() {
int arr[]={10, 20, 30, 40, 50, 60, 70, 80, 90}, *ip=arr+4;
printf(“%d”, (-2)[ip]-10);
return 0;
}
4. What is the output printed by the following C code?
#include <stdio.h>
int main (){
char a [6] = “gate";
int i, j;
for (i = 0, j = 4; i < j; a [i] = a [j]){
i++;
j--;
}
printf ("%s", a);
}
A) A. gate
B) B. Null string
C) C. gtae
D) D. None
5. What does the following fragment of C program print?
char *p = A;
A. GATEEXAM
B. EXAM
C. EEXAM
D. None of these
6. Find the output.
int main () {
unsigned int A [3] [3] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
A. Garbage
B. 1
C. 4
D. 7
7. Find returnConsider the following C code. Assume that unsigned long
value of fun(16).
int type length is 64 bits.
unsigned int fun(unsigned int n) {
unsigned int i, j = 0, sum = 0;
for (i = n; i > 1; i = i / 2, j++) ;
for (I = n; j > 1; j = j / 2, sum++);
return sum;
}
8. Consider the following C program
#include<stdio.h>
int f(int x, int y){
x = 2*x+y;
return x;
}
int main(){
int x=2, y=2;
y=f(y,x);
x=f(x,y);
printf("%d",x);
return 0;
}
# include <stdio.h>
int main()
{
char s[7] = "1234", *p;
p = s + 2;
*p = ‘\0';
printf("%s", s);
}
A) A. 12
B) B. 120400
C) C. 1204
D) D. 1034
11. Consider the following C program.
#include <stdio.h>
int main () {
int a[4] [4] = {{1, 2, 3, 4},{6, 7, 8, 9},{11, 12, 13, 14},{16, 17,18, 19}};
printf(“%d”, *(*(a+**a-1)+2));
return 0;
}
#include <stdio.h>
int main ()
{
int i, j;
int a [8] = {10, 20, 30, 40, 50, 60, 70, 80};
return 0;
}
13. What will be output printed by the following program
#include <stdio.h>
void f (int x) {
return g(x)+h(x);
}
int main() {
f (g(20)-h(20));
return 0;
}
14. What will be output printed by the following program
#include <stdio.h>
int f() {
static int x = 1;
return --x;
}
int main() {
for (f(); f(); f())
printf("%d", f());
return 0;
}
15. What will be output printed by the following program.
x[2]=‘y’;
x[3]='\0’;
}
void main(){
f(y,y);
printf("%s%s",x,y);
}
16. What will be output printed by the following program.
void main(){
int x=1,y=2,z=3;
x=x+y-z;
z=z>>1;
z=(x==0)?(x=y<<1&0):z;
y=z;
printf("%d", z);
}
17. If A is two dimensional array, A[i]+j is same as
a) A[i][j]
b) &A[i]+j
c) &A[i][j]
d) A[j]+i
18. If A is two dimensional array, A[i][j] is same as
a) i[A][j]
b) A[j][i]
c) *(A+i)[j]
d) *(A[i]+j)
19. Predict the output of the following program.
void main()
{
int i=0;
int x[5] = {10,20,30,40,50};
for (x[i] = 0; x[i] < 5; i++)
printf("%d ", x[i])
}
20. Which of the following are valid declarations for array?
i. int a[4]={4};
ii. int a[6]={1,2,3,4,5,6};
iii. int a[6]={1,2,3,4};
iv. int a[]={4};
A. i, ii & iv
B. i, ii, iii & iv
C. i, ii, & iii
D. i, iii & iv
21. Predict the output of the following program.
#include <stdio.h>
f(A + 1);
printf("%c", 0[A]);
f(A + 1);
printf("%c", 0[A]);
int main() {
f(“abc");
return 0;
}
22. Which of the following variables are created and destroyed automatically based on scope?
A. Automatic variables
B. Register variables
C. Static variables
D. Extern Variables
23. Which of the following variables access depends on scope?
A. Automatic variables
B. Register variables
C. Static variables
D. Extern Variables
24. Predict the output of the following program.
#include <stdio.h>
void f( ) {
static int i, k;
k=(i++)+j;
printf(“%d”, i+j+k);
j++;
int main() {
f();
f();
}
25. Predict the output of the following program.
#include <stdio.h>
int f( ) {
i=i-1;
if(i>0) x=f()+1;
return x;
int main() {
printf(“%d”, f());
return 0;