# SEC-a PC Quiz-4 (April 2019)

Approved & Edited by ProProfs Editorial Team
The editorial team at ProProfs Quizzes consists of a select group of subject experts, trivia writers, and quiz masters who have authored over 10,000 quizzes taken by more than 100 million users. This team includes our in-house seasoned quiz moderators and subject matter experts. Our editorial experts, spread across the world, are rigorously trained using our comprehensive guidelines to ensure that you receive the highest quality quizzes.
| By Manipalq4
M
Manipalq4
Community Contributor
Quizzes Created: 1 | Total Attempts: 94
Questions: 54 | Attempts: 94

Settings

.

• 1.

### Which of the following is not a pointer declaration?

• A.

Char a[4];

• B.

Char a[] = {‘1’, ‘2’, ‘3’, ‘4’};

• C.

Char *str;

• D.

Char a;

D. Char a;
Explanation
The correct answer is "char a;". This is because it is declaring a variable "a" of type char, but it is not a pointer declaration. The other options are all pointer declarations - "char a[4];" is declaring an array of characters, "char a[] = {'1', '2', '3', '4'};" is declaring an array of characters and initializing it with specific values, and "char *str;" is declaring a pointer to a character.

Rate this question:

• 2.

### What will be the output? int main(){ int i = 5; int j = i / -2; int k = i % -2; printf("%d %d\n", j, k); return 0; }

• A.

-2, -1

• B.

2, 1

• C.

-2, 1

• D.

None

C. -2, 1
Explanation
The code initializes the variable i with a value of 5. Then, it calculates the value of j by dividing i by -2, resulting in -2. Next, it calculates the value of k by taking the remainder of i divided by -2, which is 1. Finally, it prints the values of j and k, which are -2 and 1 respectively.

Rate this question:

• 3.

### What will be the output/error? int main(){ float i = 6.2; float j = i % -2; printf("%d\n", j); return 0; }

• A.

1

• B.

-1

• C.

Error

• D.

None

C. Error
Explanation
The code will produce an error. This is because the modulus operator (%) can only be used with integer operands, and in this case, the operands are floats. Therefore, the code will fail to compile and produce an error.

Rate this question:

• 4.

### What will be the output/error? int main() { int a = 10, b = 20, c = 30; if(!a >= 50) b = 300; c = 400; printf("%d,%d,%d", a, b, c); return 0; }

• A.

102030

• B.

1020400

• C.

10300400

• D.

103020

B. 1020400
Explanation
The output will be 1020400. This is because the if statement checks if the negation of a (which is false) is greater than or equal to 50. Since it is false, the code inside the if statement is not executed. Therefore, b remains unchanged at 20 and c is assigned the value of 400. Finally, the values of a, b, and c are printed as 10, 20, and 400 respectively.

Rate this question:

• 5.

### How to catch multi word string using scanf ?

• A.

%[^\n]s

• B.

%[^/n]s

• C.

%[/n]s

• D.

None

A. %[^\n]s
Explanation
This answer suggests using the format specifier "%[^]s" to catch a multi-word string using scanf. The caret symbol (^) followed by the square brackets ([^]s) indicates that scanf should read characters until it encounters the specified delimiter ( or >). The "s" at the end indicates that the input should be stored as a string.

Rate this question:

• 6.

### What will be the output/error? void fun(int*); int main() {        int i = 10;        int *j = &i;        fun(j++);        return 0; }  void fun(int *k) {        printf("%d\n", *k); }

• A.

10

• B.

Some garbage value

• C.

Error

• D.

None

A. 10
Explanation
The output will be 10. In the main function, the address of the variable i is assigned to the pointer j. Then, the function fun is called with the argument j++. This means that the value of j is incremented by 1 before being passed to the function. However, since the value of j is not used within the function, the increment does not affect the output. Therefore, the function prints the value at the address stored in j, which is the value of i, which is 10.

Rate this question:

• 7.

### What will be the output/error? void fun(int*); int main() {        int i = 10;        int *j = &i;        fun(++j);        return 0; }  void fun(int *k) {        printf("%d\n", *k); }

• A.

10

• B.

Some garbage value

• C.

Error

• D.

None

B. Some garbage value
Explanation
The code increments the value of the pointer `j` before passing it to the `fun()` function. Inside the `fun()` function, the pointer `k` is dereferenced using `*k`, which will access the value at the memory location pointed to by `j`. Since `j` was incremented before passing it to `fun()`, it will point to some arbitrary memory location, resulting in accessing a garbage value. Therefore, the output will be some garbage value.

Rate this question:

• 8.

### void fun(int*); int main() { int i = 10; int *j = &i; fun(&i); printf("%d ", *j); return 0; } void fun(int *j) { int k=2; j=&k; printf("%d ", *j); }

• A.

10, 2

• B.

2, 10

• C.

2, 2

• D.

None

B. 2, 10
Explanation
The correct answer is "2, 10" because in the function `fun`, the pointer `j` is assigned the address of the local variable `k`. However, this assignment does not affect the value of the pointer `j` in the `main` function. Therefore, when `*j` is printed in the `main` function, it still refers to the value of `i`, which is 10.

Rate this question:

• 9.

### Void main () { int a[4] = {1,2,3,4}; max(&a[3]); } void max(int *z) { printf("%d",*z); }

• A.

1

• B.

1,2

• C.

4

• D.

3

C. 4
Explanation
The code initializes an integer array "a" with values 1, 2, 3, and 4. Then, the main function calls the "max" function, passing the address of the element at index 3 (which is 4) as the argument. The "max" function receives the address and prints the value at that address, which is 4. Therefore, the correct answer is 4.

Rate this question:

• 10.

### Void main () { int a[4] = {1,2,3,4}; max(a[2]); } void max(int z) { printf("%d",*z); }

• A.

1

• B.

2

• C.

4

• D.

3

D. 3
Explanation
The correct answer is 3 because the function max is called with the argument a[2], which has a value of 3. Inside the max function, the value of z is printed using the * operator, which dereferences the pointer and prints the value it points to. Therefore, the output will be 3.

Rate this question:

• 11.

### Void main () { int a[4] = {1,2,3,4}, i; for(i=0; i < 4 ; i++) { max(&a[i]); } } void max(int *z) { int i; printf("%d",*z); }

• A.

1,2,3,4

• B.

2,1,3,4

• C.

2,2,2,2

• D.

3,3,3,3

A. 1,2,3,4
Explanation
The given code defines an array 'a' with four elements and initializes it with the values 1, 2, 3, and 4. It also declares a variable 'i'. The for loop iterates over the array elements and calls the function 'max' with the address of each element as an argument. The 'max' function receives the address of an element and prints its value. Therefore, the output will be the values of the array elements in the order they appear in the array: 1, 2, 3, 4.

Rate this question:

• 12.

### Void main () {  int a[4] = {1,2,3,4}, i;  max(a); } void max(int z[]) { int i;    for(i=0; i < 4; i++)    {        printf("%d\n", z[i]);            } }

• A.

4,3,2,1

• B.

1,2,3,4

• C.

3,2,1,4

• D.

2,1,3,4

B. 1,2,3,4
Explanation
The code defines an array "a" with values {1,2,3,4} and a function "max" that takes an integer array as input. The main function calls the max function passing the array "a" as an argument. The max function then loops through the elements of the input array and prints them in reverse order. Therefore, the output will be the elements of the array "a" in reverse order, which is 4,3,2,1.

Rate this question:

• 13.

### Size of pointer in gcc32 compiler is

• A.

2Byte

• B.

4Byte

• C.

8Byte

• D.

Compiler depended

B. 4Byte
Explanation
The size of a pointer in a gcc32 compiler is 4 bytes. This is because in a 32-bit system, memory addresses are represented using 32 bits, which is equivalent to 4 bytes. Therefore, a pointer, which holds the memory address of a variable, also needs to be 4 bytes in size in order to store the address properly.

Rate this question:

• 14.

### Void main () { int a[4] = {1,2,3,4}, i; max(a); } void max(int *z) { int i; for(i=0;i < 4 ; i++) { printf("%d\n", z[i]); } }

• A.

2,1,3,4

• B.

2,4,3,1

• C.

1,2,3,4

• D.

None

C. 1,2,3,4
Explanation
The given code defines an array "a" with elements [1,2,3,4] and a variable "i". It then calls the function "max" passing the array "a" as an argument. In the "max" function, a loop is used to iterate over the elements of the array and print them. Since the loop starts from 0 and goes up to 3 (less than 4), it will print all the elements of the array in the order they are stored, which is [1,2,3,4]. Therefore, the correct answer is "1,2,3,4".

Rate this question:

• 15.

### Void main () {  int a[4] = {1,2,3,4}, i;  max(&a); } void max(int *z) { int i;    for(i=3;i>=0;i++)    {        printf("%d\n", z[i]);            } }

• A.

1,2,3,4

• B.

4,3,2,1

• C.

2,1,3,4

• D.

4,3,1,2

B. 4,3,2,1
Explanation
The code defines an array "a" with values {1,2,3,4} and a variable "i". It then calls the function "max" and passes the address of the array "a" as an argument.

The function "max" takes a pointer as a parameter and uses a for loop to iterate through the array in reverse order. It prints each element of the array in a new line using printf.

Since the array "a" is {1,2,3,4} and the loop starts from index 3 and goes down to 0, the elements are printed in reverse order.

Therefore, the output will be 4,3,2,1.

Rate this question:

• 16.

### Void main () { int a=10; int *p = &a; int **q = &p; printf("%d, %d", *p, **q); }

• A.

10,10

• B.

• C.

• D.

None

A. 10,10
Explanation
The code declares an integer variable 'a' with a value of 10. It then declares a pointer variable 'p' and assigns the address of 'a' to it. Next, it declares a double pointer variable 'q' and assigns the address of 'p' to it. Finally, it prints the value pointed to by 'p' (which is 10) and the value pointed to by the pointer pointed to by 'q' (which is also 10). So, the output will be "10, 10".

Rate this question:

• 17.

### Which of the following is a correct format for declaration of function?

• A.

Return-type function-name(argument type);

• B.

Return-type function-name(argument type){}

• C.

Return-type (argument type)function-name;

• D.

All of the mentioned

A. Return-type function-name(argument type);
Explanation
The correct format for the declaration of a function is "return-type function-name(argument type);". This format includes the return type of the function, the name of the function, and the type of the argument(s) that the function accepts. This format is commonly used in programming languages to declare functions before they are defined or implemented.

Rate this question:

• 18.

### Which of the following function declaration is illegal?

• A.

Int 1bhk(int);

• B.

Int 1bhk(int a);

• C.

Int 2bhk(int*, int []);

• D.

All of the mentioned

D. All of the mentioned
Explanation
The given answer is correct because all of the mentioned function declarations are illegal. In C++, function names cannot start with a number. Therefore, both "1bhk" and "2bhk" are invalid function names.

Rate this question:

• 19.

### Which function definition will run correctly?

• A.

Int sum(int a, int b) return (a, b);

• B.

Int sum(int a, int b) {return (a + b);}

• C.

Int sum(a, b) return (a + b);

• D.

none of the mentioned

B. Int sum(int a, int b) {return (a + b);}
Explanation
The correct answer is "int sum(int a, int b) {return (a + b);}". This is the correct function definition because it follows the proper syntax for defining a function in C++. It specifies the return type (int), the function name (sum), and the parameters (int a, int b). The function body is enclosed in curly braces and correctly returns the sum of the two parameters.

Rate this question:

• 20.

### The value obtained in the function is given back to main by using ________ keyword.

• A.

Return

• B.

Static

• C.

New

• D.

Volatile

A. Return
Explanation
The value obtained in the function is given back to main by using the "return" keyword. This keyword is used to exit the function and return a value to the calling function, in this case, the main function. It allows the function to pass a result or data back to the caller, which can then be used for further computation or processing.

Rate this question:

• 21.

### Can we use a function as a parameter of another function? [ Eg: void wow(int func()) ].

• A.

Yes, and we can use the function value conveniently

• B.

Yes, but we call the function again to get the value, not as convenient as in using variable

• C.

No, C does not support it

• D.

This case is compiler dependent

C. No, C does not support it
Explanation
In C, it is not possible to use a function as a parameter of another function. C does not support passing functions as arguments to other functions. This is a limitation of the C programming language.

Rate this question:

• 22.

### 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("%sn", t); }

• A.

AB

• B.

Cd

• C.

Ef

• D.

Gh

D. Gh
Explanation
The code defines a function `f` that takes a pointer to a pointer to a character as an argument. In the `main` function, an array of character pointers `argv` is defined and passed to the `f` function. Inside the `f` function, the pointer `p` is incremented by the size of an integer (sizeof(int)) and then decremented by 1. This means that `p` now points to the fourth element of the `argv` array, which is "gh". The value of `t` is then assigned to this pointer, and it is printed using `printf`. Therefore, the output will be "gh".

Rate this question:

• 23.

### int main() { int a[5] = {1,2,3,4,5}; int *ptr = (int*)(&a+1); printf("%d %d", *(a+1), *(ptr-1)); return 0; }

• A.

Garbage Value

• B.

Compile time error

• C.

2 3

• D.

2 5

D. 2 5
Explanation
The given code snippet declares an array `a` of size 5 and initializes it with values 1, 2, 3, 4, and 5. Then, a pointer `ptr` is declared and assigned the address of the array `a` incremented by 1 (which points to the memory location just after the end of the array).

When `*(a+1)` is printed, it accesses the value at the second index of the array `a`, which is 2.

When `*(ptr-1)` is printed, it accesses the value at the memory location just before the array `a`, which is outside the bounds of the array. This results in undefined behavior and can give a garbage value or crash the program. In this case, it gives the value 5.

Therefore, the correct answer is "2 5".

Rate this question:

• 24.

### #define R 10 #define C 20 int main() { int (*p)[R][C]; printf("%d", sizeof(*p)); getchar(); return 0; }

• A.

400

• B.

200

• C.

800

• D.

1024

C. 800
Explanation
The code declares a pointer variable `p` to a 2D array with dimensions R and C. The `sizeof(*p)` returns the size of the dereferenced pointer, which is equivalent to the size of the 2D array. Since R is defined as 10 and C is defined as 20, the size of the 2D array is 10 * 20 * sizeof(int), which is 800 bytes. Therefore, the correct answer is 800.

Rate this question:

• 25.

### Int fun(int *c) { int q = 10; c = &q; return *c; } int main() { int r = 20; int *p = &r; *p=fun(p); printf("%d", *p); return 0; }

• A.

1024

• B.

10

• C.

Compile time error

• D.

Run time error

B. 10
Explanation
The function `fun` takes a pointer `c` as its parameter. Inside the function, a variable `q` is declared and assigned the value 10. Then, the pointer `c` is assigned the address of `q`. Finally, the function returns the value pointed to by `c`, which is 10. In the `main` function, a variable `r` is declared and assigned the value 20. A pointer `p` is then initialized with the address of `r`. The line `*p=fun(p)` calls the `fun` function and assigns the returned value (10) to the memory location pointed to by `p`, which is `r`. Therefore, the value of `r` is changed to 10. The `printf` statement then prints the value of `r`, which is 10.

Rate this question:

• 26.

### Void fun(int *p) { int q = 10; p = &q; } int main() { int r = 20; int *p = &r; fun(p); printf("%d", *p); return 0; }

• A.

Compile time error

• B.

10

• C.

20

• D.

Run time error

C. 20
Explanation
The correct answer is 20 because the function fun() takes a pointer as an argument and assigns the address of a local variable q to it. However, since p is a local variable in the main() function, the assignment in fun() does not affect the value of p in the main() function. Therefore, when *p is printed in the main() function, it still refers to the original variable r, which has a value of 20.

Rate this question:

• 27.

### int main() { int x = 10; int *y, **z; y = &x; z = &y; printf("x = %d, y = %d, z = %d\n", x, *y, **z); return 0; }

• A.

X=10 y=10 z=10

• B.

X=20 y=10 z=210

• C.

X=0 y = 10 z= 10

• D.

Error

A. X=10 y=10 z=10
Explanation
The given code declares an integer variable x and two integer pointers y and z. The variable x is assigned a value of 10. The pointer y is assigned the address of x using the address-of operator (&). The pointer z is assigned the address of y.

The printf statement prints the values of x, *y, and **z. Since y is pointing to x, *y dereferences the pointer and gives the value of x, which is 10. Similarly, **z dereferences the pointer z and then dereferences the pointer y, giving the value of x, which is also 10. Therefore, the output will be x=10, y=10, z=10.

Rate this question:

• 28.

### int main() { int a = 5; int *ptr ; ptr = &a; *ptr = *ptr * 3; printf("%d", a); return 0; }

• A.

10

• B.

15

• C.

20

• D.

25

B. 15
Explanation
The code declares a variable 'a' and a pointer 'ptr'. The pointer 'ptr' is assigned the address of 'a'. Then, the value stored at the address pointed by 'ptr' is multiplied by 3 and stored back in the same location. Finally, the value of 'a' is printed, which is 15.

Rate this question:

• 29.

### int main() { int a[] = { 1, 2, 3, 4, 5} ; int *ptr; ptr = a; printf(" %d ", *( ptr + 1) ); return 0; }

• A.

2,3,4,1

• B.

2, 1, 4, 3

• C.

4,3,1,2

• D.

1,2,3,4

B. 2, 1, 4, 3
Explanation
The correct answer is 2, 1, 4, 3.

In the given code, an array "a" is initialized with values 1, 2, 3, 4, 5.
A pointer variable "ptr" is declared.
The pointer "ptr" is then assigned the address of the first element of the array "a".
The expression "*(ptr + 1)" is used to access the value at the address of the second element of the array.
So, the output will be the value at the second element of the array, which is 2.
Then, the program returns 0.

Rate this question:

• 30.

### Int f(int *p, int n) { if (n  <= 1) return 0; else return max(f(p+1,n-1),p[0]-p[1]); } int main() { int a[] = {3,5,2,6,4}; printf("%d", f(a,5)); }

• A.

2

• B.

4

• C.

3

• D.

5

C. 3
Explanation
The function f takes an array of integers and its size as input. It recursively calculates the maximum difference between consecutive elements in the array. If the size of the array is less than or equal to 1, it returns 0. Otherwise, it compares the difference between the first two elements with the maximum difference between the remaining elements (calculated by calling the function recursively with a pointer to the second element and size decremented by 1). The function returns the maximum of these two values. In the given code, the array [3,5,2,6,4] is passed to f with a size of 5, and the function returns 3.

Rate this question:

• 31.

### int f(int n, int k) { if (n == 0) return 0; else if (n % 2) return f(n/2, 2*k) + k; else return f(n/2, 2*k) - k; } int main () { printf("%d", f(20, 1)); return 0; }

• A.

20

• B.

9

• C.

5

• D.

8

B. 9
Explanation
The function f(n, k) is recursively called with n/2 and 2*k as arguments. In each recursive call, the value of k is multiplied by 2.

In the given code, the initial call to f(20, 1) is made. Since n is not equal to 0, the else if condition is checked. As 20 is even, the else condition is executed and f(10, 2) is called. Again, the else condition is executed and f(5, 4) is called.

Now, as 5 is odd, the else if condition is executed and f(2, 8) is called. Since 2 is even, the else condition is executed and f(1, 16) is called.

Finally, as 1 is odd, the else if condition is executed and f(0, 32) is called. Since n is now 0, the base case is reached and 0 is returned.

The final output is obtained by summing all the returned values: 1 + 2 + 4 + 8 + 16 + 0 = 31. Therefore, the correct answer is 31.

Rate this question:

• 32.

### int funcf (int x); int funcg (int y); main() { int x = 5, y = 10, count; for (count = 1; count  <= 2; ++count) { y += funcf(x) + funcg(x); printf ("%d ", y); } } funcf(int x) { int y; y = funcg(x); return (y); } funcg(int x) { static int y = 10; y += 1; return (y+x); }

• A.

43 80

• B.

80 43

• C.

40 45

• D.

80 40

A. 43 80
Explanation
The code begins by initializing the variables x and y to 5 and 10 respectively. It then enters a for loop that will iterate twice. Inside the loop, the value of y is incremented by the result of funcf(x) and funcg(x).

In funcf, the variable y is assigned the value returned by funcg(x).

In funcg, the variable y is initially set to 10 and is incremented by 1 each time the function is called. It then returns the sum of y and x.

After each iteration of the loop, the value of y is printed.

Therefore, the output will be 43 and 80.

Rate this question:

• 33.

### Void f1 (int a, int b) { int c; c=a; a=b; b=c; } void f2 (int *a, int *b) { int c; c=*a; *a=*b;*b=c; } int main() { int a=4, b=5, c=6; f1(a, b); f2(&b, &c); printf (“%d”, c-a-b); return 0; }

• A.

-4

• B.

-5

• C.

-3

• D.

15

B. -5
Explanation

In the given code, the function f1 swaps the values of variables a and b using a temporary variable c. The function f2 swaps the values of the variables pointed to by the pointers a and b using a temporary variable c.

In the main function, the variables a, b, and c are initialized to 4, 5, and 6 respectively.

After calling f1(a, b), the values of a and b are swapped, so a becomes 5 and b becomes 4.

After calling f2(&b, &c), the values of b and c are swapped, so b becomes 6 and c becomes 4.

Finally, when printing c-a-b, we get 4-5-6 = -7. Therefore, the correct answer is -5.

Rate this question:

• 34.

### Write Correct function call to swap values of two variables void swap (int a, int b) { int temp; temp = a; a = b; b = temp; }

• A.

Call swap (x, y)

• B.

Call swap (&x, &y)

• C.

Swap(x,y) cannot be used as it does not return any value

• D.

Swap(x,y) cannot be used as the parameters are passed by value

D. Swap(x,y) cannot be used as the parameters are passed by value
Explanation
The correct answer is "Swap(x,y) cannot be used as the parameters are passed by value". In the given function, the parameters 'a' and 'b' are passed by value, which means that the function creates local copies of the variables 'x' and 'y'. Therefore, any changes made to 'a' and 'b' inside the function will not affect the original variables 'x' and 'y'. To swap the values of 'x' and 'y', we need to pass their addresses to the function using pointers, as shown in the second option "Call swap (&x, &y)".

Rate this question:

• 35.

### Double foo (double); int main() { double da, db; db = foo(da); } double foo(double a) { return a; }

• A.

Compiler errors

• B.

Some compiler-warnings not leading to unintended results

• C.

No compile warning or error

• D.

Some compiler-warnings due to type-mismatch eventually leading to unintended results

A. Compiler errors
Explanation
The code provided will result in compiler errors. This is because the function `foo` is called in the main function before it is declared. In C++, functions must be declared before they are called. To fix this error, the declaration of `foo` should be placed before the `main` function.

Rate this question:

• 36.

### Void foo(int n, int sum) { int k = 0, j = 0; if (n == 0) return; k = n % 10; j = n / 10; sum = sum + k; foo (j, sum); printf ("%d,", k); } int main () { int a = 2048, sum = 0; foo (a, sum); printf ("%dn", sum); getchar(); }

• A.

8, 4, 0, 2, 14

• B.

2, 0, 4, 8, 0

• C.

2, 0, 4, 8, 14

• D.

8, 4, 0, 2, 0

B. 2, 0, 4, 8, 0
Explanation
The given code is a recursive function that takes an integer 'n' and a sum as input. It separates the last digit of 'n' and adds it to the sum. Then, it recursively calls the function with the remaining digits of 'n'. Finally, it prints the last digit of 'n' in reverse order.

In the main function, it initializes 'a' as 2048 and 'sum' as 0. It calls the foo function with 'a' and 'sum' as arguments. After the function returns, it prints the value of 'sum'.

The output of the code will be 2, 0, 4, 8, 0. This is because the function separates the digits of 'a' in reverse order and adds them to the sum. The printf statement in the foo function prints the digits in reverse order.

Rate this question:

• 37.

### What will be the size of this array in term of memory byte? char a[20];

• A.

Error

• B.

Computation Not Possible

• C.

20 Bytes

• D.

10 Bytes

C. 20 Bytes
Explanation
The size of the array "a" in terms of memory bytes will be 20 Bytes. This is because the array is declared as "char a[20]", indicating that it can hold 20 elements of type char. Since the size of a char data type is typically 1 byte, multiplying the number of elements (20) by the size of each element (1 byte) gives us a total size of 20 Bytes.

Rate this question:

• 38.

### What will be the outpur of this code? void main() {int a[]={1,2,3,4,5}; printf("%d",a[5])}

• A.

5

• B.

4

• C.

2

• D.

0

D. 0
Explanation
The code is attempting to print the value at index 5 of the array 'a', but since arrays in C are zero-indexed, the valid indexes for this array are 0 to 4. Therefore, accessing index 5 is out of bounds and will result in undefined behavior. In this particular case, it seems that the value at index 5 happens to be 0, so that is what gets printed.

Rate this question:

• 39.

### Which declaration is incorrect?

• A.

Int a[2][2]

• B.

Int a[2][]

• C.

Int a[][2]

• D.

None

B. Int a[2][]
Explanation
The declaration "int a[2][]" is incorrect because it does not specify the size of the second dimension of the array. In C++, when declaring a multidimensional array, all dimensions except the first one must have a size specified. In this case, the size of the second dimension is missing, making the declaration invalid.

Rate this question:

• 40.

### What does the following declaration mean? int (*ptr)[10]

• A.

Ptr is array of pointers to 10 integers

• B.

Ptr is a pointer to an array of 10 integers

• C.

Ptr is an array of 10 integers

• D.

All of the mentioned

B. Ptr is a pointer to an array of 10 integers
Explanation
The declaration "int (*ptr)[10]" means that ptr is a pointer to an array of 10 integers. This means that ptr can store the memory address of an array that contains 10 integers.

Rate this question:

• 41.

### In C, if you pass an array as an argument to a function, what actually gets passed?

• A.

The value at first index

• B.

• C.

• D.

None

A. The value at first index
Explanation
When an array is passed as an argument to a function in C, what actually gets passed is the base address of the array. This means that the memory address of the first element of the array is passed to the function. From this base address, the function can access and manipulate the elements of the array using pointer arithmetic. The value at the first index of the array is not directly passed as an argument.

Rate this question:

• 42.

### int main() { int arr[1]={10}; printf("%d", 0[arr]); return 0; }

• A.

1

• B.

10

• C.

0

• D.

Error

B. 10
Explanation
In C, array elements can be accessed using the index notation arr[index]. However, this notation can be rewritten as index[arr]. In the given code, the expression 0[arr] is used to access the element at index 0 of the array arr. Since arr[0] is equal to 10, the expression 0[arr] is also equal to 10. Therefore, the output of the code will be 10.

Rate this question:

• 43.

### int main() {    int arr[] = {12, 14, 15, 23, 45};    printf("%u, %u", arr, &arr);    return 0; } // Base address is 65486

• A.

65486, 65488

• B.

65486, 65486

• C.

65486, 65490

• D.

Error

B. 65486, 65486
Explanation
The correct answer is 65486, 65486. In the printf statement, arr is the base address of the array and &arr is the address of the base address. Both arr and &arr will have the same value, which is the base address of the array, 65486.

Rate this question:

• 44.

### int main() { float arr[] = {12.4, 2.3, 4.5, 6.7}; printf("%d", sizeof(arr)/sizeof(arr[0])); return 0; }

• A.

5

• B.

4

• C.

6

• D.

7

B. 4
Explanation
The code is calculating the size of the array "arr" by dividing the total size of the array by the size of each element. Since the array "arr" is declared as a float array, each element takes up 4 bytes of memory. Therefore, the total size of the array is 4 elements multiplied by 4 bytes per element, resulting in 16 bytes. To calculate the number of elements in the array, the total size of the array is divided by the size of each element, which is 16 bytes divided by 4 bytes per element, resulting in 4.

Rate this question:

• 45.

### int main() {    int arr[]={2, 3, 4, 1, 6};    printf("%u, %u, %u", arr, &arr[0], &arr);    return 0; }

• A.

1200, 1200, 1200

• B.

1200, 1204, 1208

• C.

1200, 1200, 1208

• D.

Error

A. 1200, 1200, 1200
Explanation
The correct answer is 1200, 1200, 1200. The array name "arr" represents the address of the first element of the array. Therefore, printing "arr" will give the address of the first element, which is 1200. Similarly, "&arr[0]" also gives the address of the first element, which is 1200. Finally, "&arr" gives the address of the entire array, which is also 1200.

Rate this question:

• 46.

### Which one of the following is one of the feature of array?

• A.

Heterogenous

• B.

Homogenous

• C.

Both

• D.

None

B. Homogenous
Explanation
Homogenous is one of the features of an array. This means that an array can only store elements of the same data type. In other words, all the elements in an array must be of the same type, such as integers, characters, or strings. This allows for efficient memory allocation and retrieval of elements in the array.

Rate this question:

• 47.

### Arguments that take input by user before running a program are called?

• A.

Main Funtion Argument

• B.

Formal argument

• C.

Command line argument

• D.

None of these

C. Command line argument
Explanation
Command line arguments are the arguments that are passed to a program when it is executed from the command line or terminal. These arguments are provided by the user before running the program and they can be used to customize the behavior of the program or provide input data. This is different from formal arguments, which are defined within the program's code, and main function arguments, which are arguments passed to the main function when the program starts. Therefore, the correct answer is "Command line argument".

Rate this question:

• 48.

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

• A.

6 5

• B.

5 5

• C.

5 6

• D.

6 6

C. 5 6
Explanation
The function `m(int *p, int *q)` is a swap function that takes two pointers as parameters. It swaps the values of the variables pointed to by `p` and `q`. In the `main()` function, `a` is initialized to 6 and `b` is initialized to 5. The `m(&a, &b)` statement calls the `m()` function and passes the addresses of `a` and `b` as arguments. This means that `p` will point to the memory location of `a` and `q` will point to the memory location of `b`. Inside the `m()` function, the values of `a` and `b` are swapped using a temporary variable `temp`. After the swap, `a` becomes 5 and `b` becomes 6. Therefore, the output of `printf("%d %d", a, b)` is "5 6".

Rate this question:

• 49.

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

• A.

0 0 0 0 0

• B.

6 5 3 0 0

• C.

Garbage values

• D.

Run time error

B. 6 5 3 0 0
Explanation
The given code defines a function "m" that takes a pointer to an integer as a parameter. Inside the function, a for loop is used to iterate over the first 5 elements of the array pointed to by "p" and print them.

In the "main" function, an integer array "a" is declared and initialized with values 6, 5, and 3. The function "m" is then called with the address of "a" as the argument.

Since the array "a" has only 3 elements initialized, the remaining 2 elements will have a default value of 0. Therefore, the output will be "6 5 3 0 0".

Rate this question:

• 50.

### void fun(int *ptr) { *ptr = 30; } int main() { int x = 20; fun(&x); printf("x = %d", x); return 0; }

• A.

10

• B.

20

• C.

30

• D.

Run time error

C. 30
Explanation
The function `fun` takes a pointer to an integer as a parameter. Inside the function, it dereferences the pointer and assigns the value 30 to the memory location pointed to by `ptr`. In the `main` function, the variable `x` is initialized with the value 20. Then, the address of `x` is passed to the `fun` function. As a result, the value of `x` is modified to 30 inside the `fun` function. Finally, the value of `x` is printed, which is 30.

Rate this question:

Related Topics