Professional Documents
Culture Documents
2. char p[20];
char *s = "string";
int length = strlen(s);
int i;
for (i = 0; i < length; i++)
p[i] = s[length — i];
printf("%s",p);
(A) gnirts
(B) gnirt
(C) string
(D) no output is printed
5. int main()
{
int a[][] = {{1,2},{3,4}};
int i, j;
for (i = 0; i < 2; i++)
for (j = 0; j < 2; j++)
printf("%d ", a[i][j]);
return 0;
}
(A) 1 2 3 4
(B) Compiler Error in line ” int a[][] = {{1,2},{3,4}};”
(C) 4 garbage values
(D) 4 3 2 1
6. char a[100][100];
Assuming that the main memory is byte-addressable and that
the array is stored starting from memory address 0, the address
of a[40][50] is: (GATE CS 2002)
(A) 4040
(B) 4050
(C) 5040
(C) 5050
Hint: base adrress+i*c*element_size+j*element size
7. # include <stdio.h>
int main()
{
int arr[] = {1, 2, 3, 4, 5, 6, 7, 8};
print(arr);
return 0;
}
(A) 1, 2, 3, 4, 5, 6, 7, 8
(B) Compiler Error
(C) 1 2
(D) Run Time Error
8. int main()
{
int i;
int arr[5] = {0};
for (i = 0; i <= 5; i++)
printf("%d ", arr[i]);
return 0;
}
(A) Compiler Error: Array index out of bound.
(B) The always prints 0 five times followed by garbage value
(C) The program always crashes.
(D) The program may print 0 five times followed by garbage
value, or may crash if address (arr+5) is invalid.
9. #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
10. # include <stdio.h>
int main()
{
char str1[] = "GeeksQuiz";
char str2[] = {'G', 'e', 'e', 'k', 's', 'Q', 'u', 'i', 'z'};
int n1 = sizeof(str1)/sizeof(str1[0]);
int n2 = sizeof(str2)/sizeof(str2[0]);
printf("n1 = %d, n2 = %d", n1, n2);
return 0;
}
A n1 = 10, n2 = 9
B n1 = 10, n2 = 10
C n1 = 9, n2 = 9
D n1 = 9, n2 = 10
int main()
{
char *str1 = "Geeks";
char *str2 = "Quiz";
swap(str1, str2);
printf("str1 is %s, str2 is %s", str1, str2);
return 0;
}
A str1 is Quiz, str2 is Geeks
B str1 is Geeks, str2 is Quiz
C str1 is Geeks, str2 is Geeks
D str1 is Quiz, str2 is Quiz
int main()
{
char *str = "GeeksQuiz";
printf("%d", fun(str));
return 0;
}
(A) 10
(B) 9
(C) 8
(D) Random Number
13. #include<stdio.h>
int main()
{
char str[] = "GeeksQuiz";
printf("%s %s %s\n", &str[5], &5[str], str+5);
printf("%c %c %c\n", *(str+6), str[6], 6[str]);
return 0;
}
(A) Runtime Error
(B) Compiler Error
(C) uiz uiz uiz
uuu
(D) Quiz Quiz Quiz
uuu
int main()
{
char str[] = "geeksskeeg";
fun(str);
puts(str);
return 0;
}
(D) gggggggg