Nepal's open education portal

EduNepal

C Programming Complete Syntax & Pointer Quick Reference Sheet

Compact exam revision cheat sheet summarizing format specifiers, pointer syntax, memory allocation, and file operations in C.

C Programming · CACS101 · Semester 1

BCA Curriculum 2079

A compact, high-yield summary of C language syntax, standard library headers, pointers, and memory layouts for rapid examination revision.


1. Format Specifiers & Escape Sequences

SpecifierTypeExample Output
%d, %iSigned Decimal Integer42
%uUnsigned Decimal Integer42
%fFloating Point (6 decimal places)3.141593
%lfDouble Precision Float3.1415926535
%cSingle Character'A'
%sString (Null-terminated)"EduNepal"
%pPointer Memory Address0x7ffee4b28
%x, %XHexadecimal representation2a / 2A

2. Dynamic Memory Allocation Functions (<stdlib.h>)

``c int *p = (int*) malloc(n * sizeof(int)); // Uninitialized memory int *q = (int*) calloc(n, sizeof(int)); // Zero-initialized memory p = (int*) realloc(p, new_size * sizeof(int)); // Resize existing block free(p); // Release heap memory back to OS p = NULL; // Avoid dangling pointer! ``


3. File Opening Modes (fopen)

ModeMeaningIf File ExistsIf File Does Not Exist
"r"Read textOpens from beginningReturns NULL (Error)
"w"Write textOverwrites / TruncatesCreates new file
"a"Append textAppends to EOFCreates new file
"rb", "wb"Binary read / writeSame as aboveSame as above
"r+"Read and writeOpens from beginningReturns NULL

Related notes

View all →

Related video lessons

View all →

Practice questions

View all →
  • Which of the following is an invalid variable name in C? (a) _salary (b) 1st_rank (c) total_sum (d) age2objective · 1 marks
  • What is the return type of the `malloc()` function in C? (a) `int*` (b) `char*` (c) `void*` (d) `float*`objective · 1 marks
  • Explain the difference between call by value and call by reference in C with suitable code snippets.short · 5 marks
  • What is recursion? Write a recursive function in C to calculate the factorial of a positive integer.short · 5 marks
  • Explain dynamic memory allocation in C. Differentiate between `malloc()` and `calloc()`. Write a C program to dynamically allocate memory for N integers, sort them in ascending order, and free the memory.long · 10 marks

View all questions for this subject →

← Back to all notes