What will be the output of the following C code? #include <stdio.h> void foo(int*); int main() { int i = 10; foo((&i)++); } void foo(int *p) { printf("%d\n", *p); }
10
Some garbage value
Compile time error
Segmentation fault/code crash
What will be the output of the following C code?
#include <stdio.h> void foo(int*); int main() { int i = 10, *p = &i; foo(p++); } void foo(int *p) { printf("%d\n", *p); }
10
Some garbage value
Compile time error
Segmentation fault
What will be the output of the following C code? #include <stdio.h> void foo(float *); int main() { int i = 10, *p = &i; foo(&i); } void foo(float *p) { printf("%f\n", *p); }
10.000000
0.000000
Compile time error
Undefined behaviour
What will be the output of the following C code?
#include <stdio.h> int main() { int i = 97, *p = &i; foo(&i); printf("%d ", *p); } void foo(int *p) { int j = 2; p = &j; printf("%d ", *p); }
2 97
2 2
Compile time error
Segmentation fault/code crash
What will be the output of the following C code?
#include <stdio.h> int main() { int i = 97, *p = &i; foo(&p); printf("%d ", *p); return 0; } void foo(int **p) { int j = 2; *p = &j; printf("%d ", **p); }
2 2
2 97
Undefined behaviour
Segmentation fault/code crash
What will be the output of the following C code?
#include <stdio.h> int main() { int i = 11; int *p = &i; foo(&p); printf("%d ", *p); } void foo(int *const *p) { int j = 10; *p = &j; printf("%d ", **p); }
Compile time error
10 10
Undefined behaviour
10 11
What will be the output of the following C code?
#include <stdio.h> int main() { int i = 10; int *p = &i; foo(&p); printf("%d ", *p); printf("%d ", *p); } void foo(int **const p) { int j = 11; *p = &j; printf("%d ", **p); }
11 11 11
11 11 Undefined-value
Compile time error
Segmentation fault/code-crash
What will be the output of the following C code? #include <stdio.h> int main() { int i = 10; int *const p = &i; foo(&p); printf("%d\n", *p); } void foo(int **p) { int j = 11; *p = &j; printf("%d\n", **p); }
11 11
Undefined behaviour
Compile time error
Segmentation fault/code-crash
Which of the following is the correct syntax to send an array as a parameter to function?
func(&array);
func(#array);
func(*array);
func(array[size]);
Which of the following can never be sent by call-by-value?
Variable
Array
Structures
Both Array and Structures
Which type of variables can have the same name in a different function?
Global variables
Static variables
Function arguments
Both static variable and function arguments
Arguments that take input by user before running a program are called?
Main function arguments
Main arguments
Command-Line arguments
Parameterized arguments
What is the maximum number of arguments that can be passed in a single function?
127
253
361
No limits in number od arguments
What will be the output of the following C code? #include <stdio.h> void m(int *p, int *q) { int temp = *p; *p = *q; *q = temp; } void main() { int a = 6, b = 5; m(&a, &b); printf("%d %d\n", a, b); }
5 6
6 5
5 5
6 6
vWhat will be the output of the following C code?
#include <stdio.h> void m(int *p) { int i = 0; for(i = 0;i < 5; i++) printf("%d\t", p[i]); } void main() { int a[5] = {6, 5, 3}; m(&a); }
0 0 0 0 0
6 5 3 0 0
Run time error
6 5 3 junk junk
What will be the output of the following C code?
#include <stdio.h> void m(int p, int q) { int temp = p; p = q; q = temp; } void main() { int a = 6, b = 5; m(a, b); printf("%d %d\n", a, b); }
5 6
5 5
6 5
6 6
What will be the output of the following C code?
#include <stdio.h> void m(int p, int q) { printf("%d %d\n", p, q); } void main() { int a = 6, b = 5; m(a); }
6
6 5
6 junk value
Compile time error
What will be the output of the following C code? #include <stdio.h> int main() { char *str = "hello, world\n"; char *strc = "good morning\n"; strcpy(strc, str); printf("%s\n", strc); return 0; }
What will be the output of the following C code? #include <stdio.h> int main() { char *str = "hello, world!!\n"; char strc[] = "good morning\n"; strcpy(strc, str); printf("%s\n", strc); return 0; }
Comment on the output of the following C code #include <stdio.h> int main() { char *str = "This" //Line 1 char *ptr = "Program\n"; //Line 2 str = ptr; //Line 3 printf("%s, %s\n", str, ptr); //Line 4 }
Memory holding “this” is cleared at line 3
Memory holding “this” loses its reference at line 3
You cannot assign pointer like in Line 3
Output will be This, Program
What type of initialization is needed for the segment “ptr[3] = ‘3’;” to work?
char *ptr = “Hello!”;
char ptr[] = “Hello!”;
both char *ptr = “Hello!”; and char ptr[] = “Hello!”;
none of the mentioned
What is the syntax for constant pointer to address (i.e., fixed pointer address)?
const *
* const
const *
none of the mentioned
What will be the output of the following C code?
#include <stdio.h> int add(int a, int b) { return a + b; } int main() { int (*fn_ptr)(int, int); fn_ptr = add; printf("The sum of two numbers is: %d", (int)fn_ptr(2, 3)); }
Compile time error, declaration of a function inside main
Compile time error, no definition of function fn_ptr
Compile time error, illegal application of statement fn_ptr = add
No Run time error, output is 5
What is the correct way to declare and assign a function pointer?
(Assuming the function to be assigned is "int multi(int, int);")
int (*fn_ptr)(int, int) = multi;
int *fn_ptr(int, int) = multi;
int *fn_ptr(int, int) = &multi;
none of the mentioned
Calling a function f with a an array variable a[3] where a is an array, is equivalent to __________