Govt. Exams
Entrance Exams
Array names decay to pointers to their first element in most contexts. 'arr' is equivalent to &arr[0] and cannot be reassigned.
int arr[5]; for(int i=0; i
Loop runs from i=0 to i=4, executing 5 times total. All array elements are initialized to 0.
int occupies 4 bytes. Array size is 3×4 = 12 elements. Total: 12 × 4 = 48 bytes.
strlen() is the standard library function defined in string.h that returns the length of a string excluding the null terminator.
A char array of size 50 can store maximum 49 characters because the last position is reserved for the null terminator '\0'.
int arr[] = {10, 20, 30, 40};
int *p = arr;
printf("%d", p[2]);
p points to arr[0]. p[2] is equivalent to *(p+2), which points to arr[2] = 30.
int arr[3][3] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
printf("%d", arr[1][2]);
arr[1][2] refers to row 1, column 2, which contains 6.
char *str = "Hello";
printf("%c", str[1]);
str[1] accesses the second character of the string, which is 'e'.
10 rows × 20 columns × 4 bytes per int = 800 bytes (assuming 4-byte integer).
strlen() returns the length of the string excluding the null terminator. "Hello" has 5 characters.