Arrays and Pointers in C: 7 GATE Mistakes That Cost Marks
Stop treating arrays and pointers as interchangeable. Trace seven common C mistakes through small examples involving types, addresses, bounds and side effects.
KnowledgeGate Team
Exam prep & CS education

Arrays and pointers often print the same address, so it is tempting to treat them as interchangeable. That shortcut fails as soon as decay, precedence, row size or an array boundary changes the expression's meaning. Here are seven corrections, each proved with a small state trace instead of a rule to memorise. Before evaluating any expression, write the declared type, object size, current pointer target and valid index range.
1. C array declarations: an array name is not a modifiable pointer
Why it happens: With int a[3] = {5, 10, 15}; int *p = a;, both a in a value context and p point to a[0]. A sketch makes them look identical. The Arrays and Pointers in C: Memory, Arithmetic, Traps guide develops the model.
What goes wrong: p++ is valid and moves p to a[1], whose value is 10. But a++ is a constraint violation. The name a identifies an array object and is not a modifiable lvalue.
What to do instead: Label a as an array of three int values and p as a pointer to int. Increment or assign the pointer variable. The array remains {5, 10, 15}.
2. Array decay and sizeof: calculate length before the function call
Why it happens: An array expression usually converts to a pointer to its first element. The parameter void inspect(int a[]) is adjusted to void inspect(int *a). Arrays and Strings in C: Decay, sizeof and 2D Addresses owns the decay, sizeof and 2D address model; this post applies those rules to seven exam mistakes.
What goes wrong: Assume sizeof(int) = 4 and sizeof(int *) = 8. In the caller, int a[5] = {4, 7, 11, 18, 29} gives sizeof a = 20 and sizeof a[0] = 4, so its length is 20 / 4 = 5. Inside inspect, pointer a gives sizeof a = 8, so 8 / 4 = 2, not the array length.
What to do instead: Calculate the count while the array type is visible, then call inspect(a, 5). Pointer size is implementation-defined. Eight bytes is an assumption here.
3. Pointer arithmetic: advance by elements, not raw bytes
Why it happens: In p + 3, the 3 can look like a three-byte increment. Use int a[5] = {4, 7, 11, 18, 29}, base address 1000 and sizeof(int) = 4.
What goes wrong: Address 1003 ignores the pointed-to type. For int *p = a, the calculation is 1000 + 3 × 4 = 1012. Therefore, *(p + 3) = a[3] = 18. By contrast, ((char *)p) + 3 has assumed address 1003 because sizeof(char) = 1.
What to do instead: Write new address = base + index × sizeof(pointed-to type). Check that the result points to a valid element before dereferencing it. The numeric addresses are teaching assumptions, not portable facts.
4. Pointer increment precedence: separate movement from mutation

Why it happens: *p++, (*p)++ and *++p use the same symbols but bind differently. Start with int v[3] = {10, 20, 30}; int *p = v;, assumed addresses 4000, 4004, 4008, and sizeof(int) = 4.
What goes wrong: Treating all three as “increment the value” loses pointer position and side effects. int x = *p++; means x = 10, then p = &v[1]. Next, int y = (*p)++; means y = 20, then v[1] = 21, while p stays at &v[1]. int z = *++p; first moves p to &v[2], then gives z = 30. The final array is {10, 21, 30}.
What to do instead: Insert the implied parentheses, *(p++), (*p)++ and *(++p), then record the pointer after each expression. For more practice, use Pointers in C for GATE: Memory Diagrams and Output Traces.
![Three-row pointer trace showing x = *(p++), y = (*p)++, and z = *(++p), with p moving from v[0] to v[2] and v[1] changing to 21.](https://cdn.knowledgegate.ai/blog-assets/blog_asset_1786748276073_g223mn.jpg)
5. Array bounds: one-past is a sentinel, not an element
Why it happens: For int a[4] = {3, 6, 9, 12}, the pointer a + 4 is valid to form and compare, so it may look safe to dereference.
What goes wrong: for (i = 0; i <= 4; i++) sum += a[i]; attempts to read a[4]. Only indices 0 through 3 are valid. The C standard does not define a result for this read. It guarantees neither garbage nor a crash.
What to do instead: Set int *end = a + 4 and use for (p = a; p < end; p++) sum += *p;. This gives 3 + 6 + 9 + 12 = 30. Compare end; never dereference it. For broader context, see GATE CS Exam Preparation.
6. Two-dimensional arrays: preserve the row-pointer type
Why it happens: m[0][0] is an int, so related pointers may look like int * or int **. Use int m[2][3] = {{2, 4, 6}, {8, 10, 12}}, with &m[0][0] = 2000 and sizeof(int) = 4.
What goes wrong: In a value context, m points to an array of three int, not to int *. A row occupies 3 × 4 = 12 bytes, so m + 1 has assumed address 2000 + 12 = 2012. Passing it as int ** misreads its type and layout.
What to do instead: Use void inspect(int m[][3]) or void inspect(int (*m)[3]). Then *(*(m + 1) + 2) selects row 1, column 2. Its assumed address is 2012 + 2 × 4 = 2020, and its value is 12.
7. Character arrays and string pointers: check storage and the terminator
Why it happens: Both char s[] = "GATE"; and const char *t = "GATE"; show the same four visible characters. That hides their different storage and mutability.
What goes wrong: The array s owns five elements, {'G', 'A', 'T', 'E', '\0'}, so sizeof s = 5. A pointer's size is not a string's length. A string literal is not writable storage, and writing through a pointer to one is not permitted.
What to do instead: Use an array when characters must change. Here, s[0] = 'L' validly produces the string "LATE". Use const char * when a literal stays read-only, and include the null terminator whenever the question asks for storage size.
8. Arrays and pointers in C: the 30-second final check
Before marking an answer, run this correction checklist:
Distinguish array objects from pointer variables.
Calculate length before array decay.
Scale arithmetic by pointed-to type.
Parenthesise pointer increments.
Dereference only within valid bounds.
Preserve the full 2D row type.
Separate writable arrays from string literals.
In ten minutes, rebuild 1000 → 1012 → 18, reproduce the precedence trace ending at {10, 21, 30}, sum the bounded loop to 30, and recover address 2020 with value 12. Optional practice includes additional Arrays & Pointers questions. Then use the C Programming course for a structured pass through the wider subject.
Keep learning
Code Optimization Mistakes in Compiler Design: How to Avoid Losing GATE Marks
A rewrite that looks familiar is not necessarily safe. Trace six common optimization errors, learn why each one changes program meaning, and use a five-step check before accepting an answer.
Lexical Analysis Mistakes for GATE: 7 Mark-Losing Errors and Exact Fixes
These seven repairs show exactly where lexical analysis answers go wrong. Trace one shared source, separate token counts from lexemes and categories, and keep each compiler phase in its lane.
Grammar and CFG Mistakes for GATE: 7 Traps and How to Fix Them
Seven small grammars expose the errors that make CFG answers go wrong, with reproducible checks for classification, ambiguity, FIRST sets and CNF.
C Fundamentals Mistakes: Fix 11 Data-Type, Operator and Flowchart Errors
Short C expressions can hide strict rules. Diagnose and repair 11 common errors involving initialisation, conversions, operators, increments and flowcharts.





