ExamVeda
Login
Home
41
What will be the output of the following code?
void main()
{
      int a[10];
      printf("%d %d", a[-1], a[12]);
}
Discuss
Answer & Solution
Answer: Option D
Solution:

In c compiler does not check array with its bounds, value at the computed location is displayed.

42
What does the following declaration mean?
int (*ptr)[10];
Discuss
Answer & Solution
Answer: Option B
Solution:
The declaration int (*ptr)[10]; means that ptr is a pointer to an array of 10 integers.

Here's the breakdown:

int specifies the type of elements in the array (integers).
(*ptr) indicates that ptr is a pointer.
[10] specifies that the pointer points to an array of 10 integers.

Thus, ptr is not an array of pointers, nor an array of integers, but a pointer to an array of integers with a size of 10.
43
Array passed as an argument to a function is interpreted as
Discuss
Answer & Solution
Answer: Option C
No explanation is given for this question. Let's Discuss on Board
44
What will be the output of the program if the array begins at 65472 and each integer occupies 2 bytes?
#include<stdio.h>
void main()
{
    int a[3][4] = {1, 2, 3, 4, 4, 3, 2, 1, 7, 8, 9, 0};
    printf("%u, %u", a+1, &a+1);
}
Discuss
Answer & Solution
Answer: Option C
Solution:

>> int a[3][4] = {1, 2, 3, 4, 4, 3, 2, 1, 7, 8, 9, 0}; The array a[3][4] is declared as an integer array having the 3 rows and 4 colums dimensions.

>> printf("%u, %u\n", a+1, &a+1);
The base address(also the address of the first element) of array is 65472.
For a two-dimensional array like a reference to array has type "pointer to array of 4 ints". Therefore, a+1 is pointing to the memory location of first element of the second row in array a. Hence 65472 + (4 ints * 2 bytes) = 65480
Then, &a has type "pointer to array of 3 arrays of 4 ints", totally 12 ints. Therefore, &a+1 denotes "12 ints * 2 bytes * 1 = 24 bytes".
Hence, begining address 65472 + 24 = 65496. So, &a+1 = 65496
Hence the output of

45
What will be the output of the program?
#include<stdio.h>
int main()
{
    int arr[1] = {10};
    printf("%d", 0[arr]);
    return 0;
}
Discuss
Answer & Solution
Answer: Option C
Solution:

>> int arr[1]={10}; The variable arr[1] is declared as an integer array with size '2' i.e. arr[0] and arr[1] and it's first element is initialized to value '10'(means arr[0]=10)
and arr[1] = garbage value or zero
>> printf("%d", 0[arr]); It prints the first element value of the variable arr.

Hence the output of the program is 10.

46
What will be the output of the program if the array begins at address 65486?
#include<stdio.h>
void main()
{
    int arr[] = {12, 14, 15, 23, 45};
    printf("%u, %u", arr, &arr);
}
Discuss
Answer & Solution
Answer: Option D
Solution:

>> int arr[] = {12, 14, 15, 23, 45}; The variable arr is declared as an integer array and initialized.

>> printf("%u, %u", arr, &arr); Here,
The base address of the array is 65486.

=> arr, &arr is pointing to the base address of the array arr.
Hence the output of the program is 65486, 65486.

47
What will be the output of the program?
#include<stdio.h>
void main()
{
    float arr[] = {12.4, 2.3, 4.5, 6.7};
    printf("%d", sizeof(arr)/sizeof(arr[0]));
}
Discuss
Answer & Solution
Answer: Option B
Solution:

The sizeof function return the given variable. Example: float a=10; sizeof(a) is 4 bytes
>> float arr[] = {12.4, 2.3, 4.5, 6.7}; The variable arr is declared as an floating point array and it is initialized with the values.

>> printf("%d", sizeof(arr)/sizeof(arr[0]));
The variable arr has 4 elements. The size of the float variable is 4 bytes.
Hence 4 elements x 4 bytes = 16 bytes
sizeof(arr[0]) is 4 bytes
Hence 16/4 is 4 bytes
Hence the output of the program is '4'.

48
Which of the following is correct way to define the function fun() in the below program?
#include<stdio.h>
void main()
{
    int a[3][4];
    fun(a);
}
Discuss
Answer & Solution
Answer: Option A
Solution:

void fun(int p[][4]){ } is the correct way to write the function fun(). while the others are considered only the function fun() is called by using call by reference.

49
Which of the following statements are correct about the program below?
#include<stdio.h>
void main()
{
    int size, i;
    scanf("%d", &size);
    int arr[size];
    for(i=1; i<=size; i++)
    {
        scanf("%d", arr[i]);
        printf("%d", arr[i]);
    }
}
Discuss
Answer & Solution
Answer: Option A
Solution:

The statement int arr[size]; produces an error, because we cannot initialize the size of array dynamically. Constant expression is required here.
Example: int arr[10];
One more point is there, that is, usually declaration is not allowed after calling any function in a current block of code. In the given program the declaration int arr[10]; is placed after a function call scanf().

50
Which of the following statements are correct about an array?
1. The array int num[26]; can store 26 elements.
2. The expression num[1] designates the very first element in the array.
3. It is necessary to initialize the array at the time of declaration.
4. The declaration num[SIZE] is allowed if SIZE is a macro.
Discuss
Answer & Solution
Answer: Option B
Solution:

1. The array int num[26]; can store 26 elements. This statement is true.
2. The expression num[1] designates the very first element in the array. This statement is false, because it designates the second element of the array.
3. It is necessary to initialize the array at the time of declaration. This statement is false.
4. The declaration num[SIZE] is allowed if SIZE is a macro. This statement is true, because the MACRO just replaces the symbol SIZE with given value.
Hence the statements '1' and '4' are correct statements.