Govt Exams
char *str = "Hello";
printf("%c", *str);
*str dereferences the pointer to get the first character of the string, which is 'H'.
& is a reference operator used in C++, not in C. In C, pointers are declared using *.
A NULL pointer is a pointer that points to memory address 0, indicating it doesn't point to any valid memory location.
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.