Question 6
If 'a' is a 2D array of size 3x4 of type float, which of the following expressions is equivalent to 'a[2][3]'?
Detailed Solution
In C, multi-dimensional array subscripting a[i][j] is defined as *(*(a + i) + j).
Free Practice / PYQ
If 'a' is a 2D array of size 3x4 of type float, which of the following expressions is equivalent to 'a[2][3]'?
In C, multi-dimensional array subscripting a[i][j] is defined as *(*(a + i) + j).
What does the expression 'sizeof(arr) / sizeof(arr[0])' calculate when applied to an array declared in the same scope as 'int arr[10];'?
sizeof(arr) gives total array bytes (10 * 4 = 40), and sizeof(arr[0]) gives 4 bytes. Dividing gives 10, the total number of elements.
What happens when you execute the statement 'free(ptr);' on a pointer allocated via 'malloc'?
free(ptr) deallocates the heap memory region but does not modify the value stored inside the variable ptr itself, creating a dangling pointer.
What is the output of the following C program?
#include <stdio.h>
void fun(int *p) {
*p = 50;
}
int main(void) {
int val = 10;
fun(&val);
printf("%d", val);
return 0;
}Passing &val passes the address of 'val' to 'p'. Dereferencing *p = 50 modifies the original variable 'val' in main to 50.
Which function dynamically allocates memory on the heap and initializes all allocated bytes to zero?
calloc(num, size) allocates memory on the heap and clears all allocated memory bytes to zero, unlike malloc() which leaves uninitialized garbage.