Question 1
void fun(int *p) { int q = 10; p = &q; } int main() { int r = 20; int *p = &r; fun(p); printf("%d", *p); return 0; }
10
20
Compiler error
Runtime Error
Question 2
#include <stdio.h> #define R 10 #define C 20 int main() { int (*p)[R][C]; printf("%d", sizeof(*p)); getchar(); return 0; }
Question 3
#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; }
Question 4
#include <stdio.h> char *c[] = {"GeksQuiz", "MCQ", "TEST", "QUIZ"}; char **cp[] = {c+3, c+2, c+1, c}; char ***cpp = cp; int main() { printf("%s ", **++cpp); printf("%s ", *--*++cpp+3); printf("%s ", *cpp[-2]+3); printf("%s ", cpp[-1][-1]+1); return 0; }
Question 5
#include <string.h> #include <stdio.h> #include <stdlib.h> void fun(char** str_ref) { str_ref++; } int main() { char *str = (void *)malloc(100*sizeof(char)); strcpy(str, "GeeksQuiz"); fun(&str); puts(str); free(str); return 0; }
Question 6
#include <stdio.h> void f(char**); int main() { char *argv[] = { "ab", "cd", "ef", "gh", "ij", "kl" }; f(argv); return 0; } void f(char **p) { char *t; t = (p += sizeof(int))[-1]; printf("%s\\n", t); }
Question 8
#include <stdio.h> #include <stdlib.h> int main(void) { int i; int *ptr = (int *) malloc(5 * sizeof(int)); for (i=0; i<5; i++) *(ptr + i) = i; printf("%d ", *ptr++); printf("%d ", (*ptr)++); printf("%d ", *ptr); printf("%d ", *++ptr); printf("%d ", ++*ptr); }
Question 9
#include <stdio.h> int fun(int arr[]) { arr = arr+1; printf("%d ", arr[0]); } int main(void) { int arr[2] = {10, 20}; fun(arr); printf("%d", arr[0]); return 0; }
Question 10
What is printed by the following C program?
$include <stdio.h> int f(int x, int *py, int **ppz) { int y, z; **ppz += 1; z = **ppz; *py += 2; y = *py; x += 3; return x + y + z; } void main() { int c, *b, **a; c = 4; b = &c; a = &b; printf( "%d", f(c,b,a)); getchar(); }
18
19
21
22
There are 19 questions to complete.