Anda di halaman 1dari 4

C programming Practice Set 5

1. What is the output of the following Program?

# include <stdio.h>

void print(int arr[])


{
int n = sizeof(arr)/sizeof(arr[0]);
int i;
for (i = 0; i < n; i++)
printf("%d ", arr[i]);
}

int main()
{
int arr[] = {1, 2, 3, 4, 5, 6, 7, 8};
print(arr);
return 0;
}
A. 12345678
B. 12
C. Compiler error
D. Run time error
2. Consider the following C-function in which a[n] and b[m] are two sorted integer arrays and c[n + m]
be another integer array.

void xyz(int a[], int b [], int c[])


{
int i, j, k;
i = j = k = O;
while ((i<n) && (j<m))
if (a[i] < b[j]) c[k++] = a[i++];
else c[k++] = b[j++];
}

Which of the following condition(s) hold(s) after the termination of the while loop?

(i) j < m, k = n+j-1, and a[n-1] < b[j] if i = n


(ii) i < n, k = m+i-1, and b[m-1] <= a[i] if j = m
A. Only (i)
B. Only (ii)
C. Either (i) and (ii)
D. None of the above

: | . . | |
,
[GATE 2006]

3. Assume the following C variable declaration


int *A [10], B[10][10];
Of the following expressions
I. A[2]
II. A[2][3]
III. B[1]
IV. B[2][3]
Which will not give compile-time errors if used as left hand sides of assignment statements in a C
program (GATE CS 2003)?
A. I,II and IV only
B. II , III and IV only
C. II and IV only
D. IV only

[GATE 2003]

4. Consider the following program

#include<stdio.h>
int main()
{
int a[10][20][30] = {0};
a[5][2][1] = 2;
return 0;
}

Which of the following will print the value 2 for the above code?

A. printf("%d",*(((a+5)+2)+1));
B. printf("%d",***((a+5)+2)+1);
C. printf("%d",*(*(*(a+5)+2)+1));
D. None of these

: | . . | |
,
5. Consider a compiler where int takes 4 bytes, char takes 1 byte and pointer takes 4 bytes. What is
the printed by the following program

#include <stdio.h>

int main()
{
int arri[] = {1, 2 ,3};
int *ptri = arri;

char arrc[] = {1, 2 ,3};


char *ptrc = arrc;

printf("sizeof arri[] = %d ", sizeof(arri));


printf("sizeof ptri = %d ", sizeof(ptri));

printf("sizeof arrc[] = %d ", sizeof(arrc));


printf("sizeof ptrc = %d ", sizeof(ptrc));

return 0;
}
A. sizeof arri[] = 12 sizeof ptri = 4 sizeof arrc[] = 3 sizeof ptrc = 1
B. sizeof arri[] = 12 sizeof ptri = 8 sizeof arrc[] = 3 sizeof ptrc = 1
C. sizeof arri[] = 3 sizeof ptri = 4 sizeof arrc[] = 3 sizeof ptrc = 1
D. sizeof arri[] = 12 sizeof ptri = 8 sizeof arrc[] = 3 sizeof ptrc = 8

6. What is the printed by the following C program segment

char ptr[]= "Gatelectures.com";


char qtr[] = "GATE";
int i=0;
for( ;ptr[i++]=qtr[i++]; );
printf("%s\n",ptr);
A. AeEe
B. AaEe
C. aAeE
D. none of the above
7. What does the following C-statement declare?
( ) ( ) ;
A. A function that takes an integer pointer as argument and returns an integer.
B. A function that takes an integer as argument and returns an integer pointer.
C. A pointer to a function that takes an integer pointer as argument and returns an integer.
D. A function that takes an integer pointer as argument and returns a function pointer

: | . . | |
,
8. Assume size of an integer and a pointer is 4 byte. What does the following program prints:

#include <stdio.h>
#define R 10
#define C 20

int main()
{
int (*p)[R][C];
printf("%d", sizeof(*p));
getchar();
return 0;
}
A. 200
B. 400
C. 800
D. 1600
9. What does the following program Segment print ?

int a[5] = {1,2,3,4,5};


int *ptr = (int*)(&a+1);
printf("%d %d", *(a+1), *(ptr-1));

A. 2 5
B. Garbage value
C. Compiler error
D. Segmentation fault
10. What does the following program prints

#include <stdio.h>
void f(char **p)
{
char *t;
t = (p += sizeof(int))[-1];
printf("%s\n", t);
}
int main()
{
char *argv[] = { "ab", "cd", "ef", "gh", "ij", "kl" };
f(argv);
return 0;
}

A. gh
B. ij
C. cd
D. ef

: | . . | |
,

Anda mungkin juga menyukai