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
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
| Specifier | Type | Example Output |
|---|---|---|
%d, %i | Signed Decimal Integer | 42 |
%u | Unsigned Decimal Integer | 42 |
%f | Floating Point (6 decimal places) | 3.141593 |
%lf | Double Precision Float | 3.1415926535 |
%c | Single Character | 'A' |
%s | String (Null-terminated) | "EduNepal" |
%p | Pointer Memory Address | 0x7ffee4b28 |
%x, %X | Hexadecimal representation | 2a / 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)
| Mode | Meaning | If File Exists | If File Does Not Exist |
|---|---|---|---|
"r" | Read text | Opens from beginning | Returns NULL (Error) |
"w" | Write text | Overwrites / Truncates | Creates new file |
"a" | Append text | Appends to EOF | Creates new file |
"rb", "wb" | Binary read / write | Same as above | Same as above |
"r+" | Read and write | Opens from beginning | Returns NULL |
CS50x Introduction to C Programming Lecture (David J. Malan)
Open lesson pageLesson videos
- 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
C Programming
Overview
C Programming (CACS101) is a core credit course structured under the official university academic syllabus for Bachelor of Computer Application.
Objectives
- Equip students with deep theoretical foundations in C Programming.
- Develop practical problem-solving, laboratory, and implementation skills.
- Prepare graduates for industry careers, research, and national university examinations.
Unit structure
- Unit 1: Introduction to Programming Concepts and C Language6 hrs
By the end of Unit 1, students will be able to explain, implement, and solve problems related to Introduction to Programming Concepts and C Language.
Unit 1:Comprehensive study notes, key principles, and examples for Introduction to Programming Concepts and C Language. - Unit 2: Operators and Expressions7 hrs
By the end of Unit 2, students will be able to explain, implement, and solve problems related to Operators and Expressions.
Unit 2:Comprehensive study notes, key principles, and examples for Operators and Expressions. - Unit 3: Input and Output Operations4 hrs
By the end of Unit 3, students will be able to explain, implement, and solve problems related to Input and Output Operations.
Unit 3:Comprehensive study notes, key principles, and examples for Input and Output Operations. - Unit 4: Control Statements and Decision Making8 hrs
By the end of Unit 4, students will be able to explain, implement, and solve problems related to Control Statements and Decision Making.
Unit 4:Comprehensive study notes, key principles, and examples for Control Statements and Decision Making. - Unit 5: Arrays and String Manipulations8 hrs
By the end of Unit 5, students will be able to explain, implement, and solve problems related to Arrays and String Manipulations.
Unit 5:Comprehensive study notes, key principles, and examples for Arrays and String Manipulations. - Unit 6: Functions and Recursion7 hrs
By the end of Unit 6, students will be able to explain, implement, and solve problems related to Functions and Recursion.
Unit 6:Comprehensive study notes, key principles, and examples for Functions and Recursion. - Unit 7: Pointers and Memory Management8 hrs
By the end of Unit 7, students will be able to explain, implement, and solve problems related to Pointers and Memory Management.
Unit 7:Comprehensive study notes, key principles, and examples for Pointers and Memory Management. - Unit 8: Structures and Unions5 hrs
By the end of Unit 8, students will be able to explain, implement, and solve problems related to Structures and Unions.
Unit 8:Comprehensive study notes, key principles, and examples for Structures and Unions. - Unit 9: File Handling in C5 hrs
By the end of Unit 9, students will be able to explain, implement, and solve problems related to File Handling in C.
Unit 9:Comprehensive study notes, key principles, and examples for File Handling in C.
Learning outcomes
- Demonstrate rigorous technical knowledge and conceptual mastery of C Programming.
- Design, implement, and analyze efficient algorithms and practical frameworks.
- Solve representative theoretical proofs and complex applied problems independently.
Teaching & evaluation
Classroom lectures (3 hours/week), practical laboratory assignments (3 hours/week), and project work.
Internal Assessment (40 Marks: Theory Exam, Practical Exam, Attendance, Assignments) and Final University Board Examination (60 Marks).
Reference books
- Programming in ANSI C by E. Balagurusamy (McGraw-Hill)
- The C Programming Language by Brian Kernighan & Dennis Ritchie (Prentice Hall)
- Let Us C by Yashavant Kanetkar (BPB Publications)
Related notes
- C Programming — Complete Course Notes (BCA 1st Sem)Notes
- Unit 1: Introduction to Programming Concepts and C Language NotesNotes
- Unit 2: Operators and Expressions NotesNotes
- Unit 3: Input and Output Operations NotesNotes
- Unit 4: Control Statements and Decision Making NotesNotes
- Unit 5: Arrays and String Manipulations NotesNotes
Related video lessons
Practice questions
- 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