Computer Science

C Programming: Pointers, Arrays, and Functions

Dec 25, 202510 min read
Back to All Strategy Articles
Subject:Computer Science
C Programming: Pointers, Arrays, and Functions
Official Exam Syllabus Alignment
Target Exam: Gujarat Police Wireless PSI (WPSI) Technical Paper 2
Syllabus Module: Unit 3: Programming in C (Pointers, Memory, Structures)
Topic Weightage: 10–14 Marks
Preparation Focus: Code Tracing & Pointer Arithmetic

C is a foundational programming language. Questions in the exam often test your understanding of syntax, logic, and memory management in C.

1. Pointers

A pointer is a variable that stores the memory address of another variable. It is a powerful feature for direct memory manipulation.

  • Declaration: int *ptr;
  • Address-of Operator (&): Gets the address of a variable (e.g., ptr = &var;).
  • Dereference Operator (*): Accesses the value stored at the memory address (e.g., value = *ptr;).

2. Arrays and Strings

An array is a collection of elements of the same data type stored in contiguous memory locations. In C, the array name acts as a constant pointer to the first element.

Strings in C are simply arrays of characters, terminated by a null character ('\0').

Pass by Value vs Pass by Reference

When passing arguments to functions, 'Pass by Value' copies the value. Modifications inside the function don't affect the original variable. 'Pass by Reference' (using pointers in C) passes the memory address, allowing the function to modify the original variable.

High-Yield Practice Questions & Worked Examples

Test your understanding with these exam-standard questions specifically calibrated for the syllabus pattern:

Exam Practice MCQ 1 Target Syllabus Drill

Q: What is the output of the following C code snippet? int arr[] = {10, 20, 30, 40}; int *ptr = arr; printf("%d", *(ptr + 2));

  • (A) 10
  • (B) 20
  • (C) 30
  • (D) 40

✓ Correct Answer: (C) 30

Detailed Explanation: In C, arr decays into a pointer to its first element arr[0] (value 10). *(ptr + 2) shifts the pointer forward by 2 integer elements, pointing to arr[2], which evaluates to 30.

Exam Practice MCQ 2 Target Syllabus Drill

Q: What memory allocation function in C initializes all allocated bytes to zero?

  • (A) malloc()
  • (B) calloc()
  • (C) realloc()
  • (D) free()

✓ Correct Answer: (B) calloc()

Detailed Explanation: calloc(n, size) allocates memory for an array of n elements of size bytes and clears all memory bits to zero. malloc() leaves allocated memory uninitialized with garbage values.

Sharpen Your Exam Readiness on Mcqprepzone

Mastering technical formulas and theoretical concepts is only step one. Solving timed mock tests under exact exam conditions improves speed, eliminates negative marking, and reveals your weak spots.

Frequently Asked Questions

What is a Dangling Pointer in C?

A dangling pointer points to a memory location that has already been deallocated using free(). Accessing it causes undefined behavior or segmentation faults. It should be assigned NULL immediately after freeing.

What is the size of a pointer in C on a 64-bit operating system?

On a 64-bit system, all data pointers have a size of 8 bytes (64 bits), regardless of whether they point to a char, int, float, or custom struct.

What is the difference between a Structure and a Union in C?

In a Structure, every member has its own separate memory location, so sizeof(struct) is the sum of member sizes (plus padding). In a Union, all members share the same single memory location, so sizeof(union) is simply the size of its largest member.

Related Strategy & Syllabus Articles

Strengthen your exam preparation across adjacent subjects

All Posts

Never Miss an Exam Update

Join 50,000+ aspirants receiving our weekly Gujarat Police & GPSC strategy emails.