Govt. Exams
Entrance Exams
On a 64-bit system, a pointer is 8 bytes (64 bits) regardless of the data type it points to.
The & operator (address-of operator) returns the memory address of a variable.
char str[] = "HELLO";
int len = 0;
while(str[len] != '\0') {
len++;
}
printf("%d", len);
What will be the output?
The string "HELLO" has 5 characters. The while loop counts characters until it encounters the null terminator '\0'. The output will be 5. The null terminator is not counted in the length.
On 32-bit systems, int is typically 4 bytes. 5 elements × 4 bytes = 20 bytes total.
arr+1 points to second element (arr[1]). Dereferencing gives value 20.
Option B shows two valid ways: pointer to string literal or character array. Option A is wrong (single char), C is wrong (no String type in C).
A 2D array with dimensions [4][5] contains 4 × 5 = 20 elements total.
The syntax char *str[5] declares an array of 5 pointers, each pointing to a character (or string). The brackets bind tighter than asterisk.
Option A is valid - 2D arrays can be initialized with all elements in a single brace. Options B and C are invalid as at least one dimension must be specified.
'Hello' has 5 characters plus 1 null terminator (\0), making total 6 bytes.