Govt. Exams
Entrance Exams
char *ptr;
char str[] = "Programming";
ptr = str;
ptr[2] = 'X';
ptr points to the character array str. Modifying ptr[2] modifies str[2], changing 'o' to 'X', resulting in 'PrXgramming'.
char arr[5] = "Hello";
printf("%d", strlen(arr));
Array is too small. "Hello" needs 6 bytes including null terminator, but only 5 are allocated. This causes buffer overflow.
After allocating the array of pointers, each row must be allocated separately.
int *arr[10] declares an array of 10 pointers to int (subscript binds tighter than dereference). Use int (*arr)[10] for pointer to array.
strncpy with buffer size check and explicit null termination is the standard safe approach. Option A lacks bounds checking; C and D have issues with null termination.
ptr[3] is equivalent to arr[3] and accesses the element at address *(ptr+3). For int*, ptr+3 moves 12 bytes (3×4 bytes) in memory.
arr creates a modifiable array copy of the string. ptr points to a string literal (read-only in memory). Modifying *ptr leads to undefined behavior.
strcpy() doesn't check dest buffer size, making it unsafe. It can cause buffer overflow if src is larger than dest. Modern compilers recommend strncpy() or strlcpy().
arr[0][0] is a 1D array of 5 integers. Each int is 4 bytes, so total is 5×4=20 bytes.
char str[] = "GATE2025";
for(int i=0; str[i]!='\0'; i++)
if(i%2==0) printf("%c", str[i]);
Indices: 0(G), 2(T), 4(E), 6(2). Even indices are printed: G, T, E, 2 -> "GTE2". Wait, let me recount: G(0), A(1), T(2), E(3), 2(4), 0(5), 2(6), 5(7). Even: G, T, 2, 2. Actually "GAE2" matches indices 0,2,4 which is GTE2. Let me verify: index 0=G, 2=T, 4=2, 6=5. So GTE2. But option shows GAE2. Rechecking: str="GATE2025": G(0)A(1)T(2)E(3)2(4)0(5)2(6)5(7). Even indices: 0,2,4,6 = G,T,2,2. Hmm, this should be GT22 but that's not an option. Let me reconsider the string. Actually "GATE2025" = G-A-T-E-2-0-2-5. Indices 0,2,4,6 = G,T,2,2. Since this doesn't match, the closest is checking if question meant something else. Looking at option C "GAE2", this would be indices 0,1,2,4 which isn't all even. There might be a typo in the original. The answer should logically be "GT22" for even indices.