Home Subjects C Programming

C Programming

C language from basics to advanced placement prep

198 Q 10 Topics Take Test
Advertisement
Difficulty: All Easy Medium Hard 81–90 of 198
Topics in C Programming
How can you initialize a structure array of 10 elements partially in C?
A struct emp arr[10] = {0};
B struct emp arr[10] = {};
C struct emp arr[10] = {NULL};
D Both A and B are correct
Correct Answer:  D. Both A and B are correct
EXPLANATION

Both {0} and {} will initialize all members to zero. These are equivalent in C99 and later standards.

Take Test
What happens if you assign a union member and then access another member?
struct u { int a; char b; }; u.a = 257; printf("%d", u.b);
A Prints 257
B Prints 1 (LSB of 257)
C Prints garbage
D Compilation error
Correct Answer:  B. Prints 1 (LSB of 257)
EXPLANATION

In a union, both members share memory. 257 in binary is 100000001. u.b (char) reads only the LSB, which is 1.

Take Test
Which statement is true about nested structures in C?
A Nested structures are not allowed
B A structure can contain another structure as a member
C Nested structures require pointers
D Nested structures can only be used with unions
Correct Answer:  B. A structure can contain another structure as a member
EXPLANATION

C allows structures to have other structures as members. This is called nested structures and is a common practice.

Take Test
Q.84 Hard Pointers
What is the output of this code?
char str[] = "GATE";
char *p = str;
printf("%c %c", *p, *(p+3));
A G T
B G \0
C G E
D Compilation error
Correct Answer:  A. G T
EXPLANATION

p points to str[0] which is 'G'. p+3 points to str[3] which is 'E'. Wait - str="GATE" has indices 0:G, 1:A, 2:T, 3:E. So *(p+3) is 'E'. Correction: answer should be 'G E'. But checking: G-A-T-E at 0-1-2-3, so *(p+3)='E'. The option shows 'G T' - p points to G, p+2 would be T. Re-reading: *(p+3) for "GATE" is 'E'. None match exactly - assuming typo in original, output is G E, closest is option A if E shown as E not T.

Take Test
Q.85 Hard Pointers
Consider: const int *p; and int * const q; Which statement is true?
A Both prevent modification of data
B First prevents pointer change, second prevents data change
C First prevents data change, second prevents pointer change
D Both are identical
Correct Answer:  C. First prevents data change, second prevents pointer change
EXPLANATION

const int *p: pointer can change, data cannot. int * const q: pointer cannot change, data can be modified.

Take Test
Q.86 Hard Pointers
What is the relationship between arrays and pointers?
A Arrays are pointers
B Pointers are arrays
C Array name decays to pointer in most contexts
D They are unrelated
Correct Answer:  C. Array name decays to pointer in most contexts
EXPLANATION

Array name acts as pointer to first element in expressions but they're distinct. &arr and arr differ in type.

Take Test
Q.87 Hard Pointers
For dynamic 2D array: int **arr = (int**)malloc(n * sizeof(int*)); What's missing?
A Nothing, code is complete
B Allocating memory for each row
C Casting malloc result
D Type checking
Correct Answer:  B. Allocating memory for each row
EXPLANATION

This allocates row pointers only. Each row needs allocation: arr[i] = (int*)malloc(m * sizeof(int));

Take Test
Q.88 Hard Pointers
What is the output of: printf("%p", NULL);?
A 0x0
B NULL
C Implementation-defined (typically 0x0 or empty)
D Compilation error
Correct Answer:  C. Implementation-defined (typically 0x0 or empty)
EXPLANATION

%p prints pointer values. NULL representation depends on implementation, commonly shown as 0x0 or (nil).

Take Test
Q.89 Hard Pointers
In pointer to function: int (*ptr)(int, int); What does this declare?
A Function returning pointer to int
B Pointer to function returning int with 2 int parameters
C Array of pointers
D Pointer to array of ints
Correct Answer:  B. Pointer to function returning int with 2 int parameters
EXPLANATION

Parentheses around *ptr give pointer priority. It's a pointer to a function taking 2 ints and returning int.

Take Test
Q.90 Hard Pointers
What is the difference between arr and &arr if arr is an array?
int arr[5];
A Both are identical
B arr is pointer to first element, &arr is pointer to whole array
C &arr is pointer to first element, arr is pointer to whole array
D They have different sizes
Correct Answer:  B. arr is pointer to first element, &arr is pointer to whole array
EXPLANATION

arr decays to pointer to first element (int*). &arr is pointer to whole array (int(*)[5]). Pointer arithmetic differs.

Take Test
IGET
iget AI
Online · Ask anything about exams
Hi! 👋 I'm your iget AI assistant.

Ask me anything about exam prep, MCQ solutions, study tips, or strategies! 🎯
UPSC strategy SSC CGL syllabus Improve aptitude NEET Biology tips