C Programming Detailed Revision Notes
Introduction to C
C is a general-purpose, procedural programming language developed by Dennis Ritchie in 1972 at
Bell Labs. It is widely used in system software, embedded systems, and application development.
Features include portability, efficiency, rich library support, and flexibility. C serves as the base for
many modern languages such as C++, Java, and Python.
• Q: Who developed C and in which year?
• Q: Write any three applications of C language.
• Q: Explain two features of C that make it powerful.
• Q: Differentiate between high-level and low-level languages.
• Q: Why is C called a middle-level language?
Data Types and Variables
Data types define the type of data that can be stored in a variable. Basic data types: int, float, char,
double, void. Variables are named memory locations used to store data. Constants are fixed values
that do not change during execution.
• Q: List all basic data types in C with size (in bytes).
• Q: Write a program snippet to declare and initialize variables of type int, float, and char.
• Q: Differentiate between variable and constant in C.
• Q: What is the purpose of 'typedef'?
• Q: Explain scope and lifetime of a variable in C.
Operators in C
Operators are special symbols that perform operations on operands. Types: Arithmetic (+,-,*,/,%),
Relational (==, !=, >, <, >=, <=), Logical (&&, ||, !), Assignment (=, +=, -=), Increment/Decrement
(++, --), Bitwise (&, |, ^, <<, >>), Ternary (?:).
• Q: Differentiate between = and == operator.
• Q: Write a program snippet using modulus operator to check even/odd.
• Q: What is the difference between logical AND (&&) and bitwise AND (&)?
• Q: Explain ternary operator with an example.
• Q: What is operator precedence? Give example.
Control Statements
Control statements alter the flow of execution in a program. Types: Conditional (if, if-else, switch),
Looping (for, while, do-while), Jump (break, continue, goto, return). Loops help in executing code
repeatedly until a condition fails.
• Q: Write a program using if-else to find the largest of two numbers.
• Q: Which loop is entry-controlled? Explain.
• Q: Differentiate between while and do-while loops.
• Q: What is the use of break and continue statements?
• Q: Write a switch-case program to print day of week (1-7).
Functions in C
A function is a block of code designed to perform a task. Functions help in modularity and
reusability. Two types: Library functions (printf, scanf, sqrt) and User-defined functions. A function
has prototype, definition, and call. Functions can return values and take arguments.
• Q: What is a function prototype?
• Q: Write a function to calculate factorial of a number.
• Q: Differentiate between call by value and call by reference.
• Q: What is recursion? Give an example.
• Q: Write a program using function to add two numbers.
Arrays in C
An array is a collection of elements of the same data type stored in contiguous memory. Syntax:
datatype array_name[size]. Arrays can be 1D, 2D (matrices), or multidimensional. Indexing starts
from 0.
• Q: Declare an array of 10 integers and initialize it.
• Q: Write a program to find the largest element in an array.
• Q: Differentiate between 1D and 2D array.
• Q: What is the index of first element in array?
• Q: Write a program to print sum of array elements.
Pointers in C
Pointers are variables that store memory addresses of other variables. Declared using '*'. Important
operators: & (address of), * (value at). Pointers allow dynamic memory allocation and efficient array
handling.
• Q: What is a pointer? Write syntax to declare a pointer.
• Q: Write a program to print address of a variable using pointer.
• Q: Differentiate between pointer and array.
• Q: What is NULL pointer?
• Q: Explain pointer arithmetic with example.
Strings in C
Strings are arrays of characters ending with null character '\0'. Standard library provides functions
like strlen, strcpy, strcat, strcmp. Strings are widely used in handling textual data.
• Q: What is a string in C?
• Q: Write a program to input and print a string.
• Q: Differentiate between gets() and scanf().
• Q: Write a program to find length of a string without using strlen().
• Q: What is the use of strcmp() function?
Structures in C
A structure is a user-defined data type that groups different types of variables. Syntax: struct
structure_name { datatype member1; datatype member2; }; Useful in representing records (like
student, employee).
• Q: Define a structure to store student details (name, roll, marks).
• Q: Differentiate between array and structure.
• Q: What is nested structure? Give example.
• Q: Write a program using structure to store and print employee details.
• Q: What is the difference between structure and union?
File Handling in C
C provides file handling through functions in . Modes: r (read), w (write), a (append), r+, w+, a+.
Functions: fopen, fclose, fprintf, fscanf, fgetc, fputc. Files allow permanent data storage.
• Q: What is the use of fopen()? Write syntax.
• Q: Differentiate between text file and binary file.
• Q: Write a program to create and write into a file.
• Q: What is EOF in file handling?
• Q: Explain difference between fprintf() and fputs().