0% found this document useful (0 votes)
4 views25 pages

C Programming - 25 Questions

The document contains a series of programming questions related to C language concepts, including array declarations, pointer types, function outputs, and variable scopes. Each question presents a code snippet or a theoretical query, followed by multiple-choice answers. The content is aimed at testing knowledge of C programming and understanding of memory management, data types, and control structures.

Uploaded by

Anbu Alwin
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views25 pages

C Programming - 25 Questions

The document contains a series of programming questions related to C language concepts, including array declarations, pointer types, function outputs, and variable scopes. Each question presents a code snippet or a theoretical query, followed by multiple-choice answers. The content is aimed at testing knowledge of C programming and understanding of memory management, data types, and control structures.

Uploaded by

Anbu Alwin
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 25

1.

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)

1. int *p; a. p is a pointer to function


2. int *p[3]; b. p is a pointer to integer
3. int (*p)[3]; c. p is an array of integer pointers
4. int (*p)( ); d. p is a pointer to integer array

A. 1-a, 2,-b, 3-c, 4-d


B. 1-b, 2,-c, 3-d, 4-a
C. 1-b, 2,-d, 3-c, 4-a
D. 1-a, 2,-c, 3-b, 4-d
3. Find the output of following program.

#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 A[] = "GATEEXAM";

char *p = A;

printf("%s", A + 3[p] - p[4]);

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}};

printf ("%u", **(A + 3) - 1);

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;
}

The value printed by the program is ______________.


9. Find the output for the function call f(2,1).

void f(int x, int y) {


int *p;
x=0;
p=&x;
y=*p;
*p=1;
printf(“%d”, x+y);
}
10. What will be output printed by the following program

# include <stdio.h>
int main()
{
char s[7] = "1234", *p;
p = s + 2;
*p = ‘\0';
printf("%s", s);
}

What will be printed by the program?

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;
}

The output of the program is _______.


12. What will be output printed by the following program

#include <stdio.h>
int main ()
{
int i, j;

int a [8] = {10, 20, 30, 40, 50, 60, 70, 80};

for(i = 0; i < 3; i++) a[i] = a[i] + 1;

for (j = 7; j > 4; j--) a[i] = a[i] - 1;

printf ("%d, %d", i, a[i]);

return 0;
}
13. What will be output printed by the following program

#include <stdio.h>

int g( int p) {return p+1; }

int h(i nt q) {return q-1; }

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.

void f(char x[], char y[]){

x[2]=‘y’;

x[3]='\0’;
}
void main(){

char x[]=“xyxy", y[]=“xy";

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>

void f(char *A) {

if (A[0] == '\0') return;

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;

auto int j=20;

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( ) {

static int i=5,x;

i=i-1;

if(i>0) x=f()+1;

return x;

int main() {

printf(“%d”, f());

return 0;

You might also like