C Programming: From Theory to Coding, Study notes of C programming

A beginner-friendly collection of C programming notes covering basic definitions, concepts, syntax, coding examples, and important programs explained in a simple and easy-to-understand manner for learning and revision.

Typology: Study notes

2025/2026

Available from 06/01/2026

ankita-chakraborty-2
ankita-chakraborty-2 🇮🇳

1 document

1 / 135

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
P a g e | 1
CONTENTS
THEOReTICAL BASED
UNIT NO. CHAPTER NAME PAGE NO.
I Introduction to C 3-6
II Variables, Data types,
Constants
7-10
III Operators and
Expressions
11-17
IV Input and Output 18-20
V Control Statements 21-27
VI Arrays 28-30
VII Strings 31-33
VIII Functions 33-36
IX Pointers 36-38
X Structures and Unions 39-40
XI File Handling 40-41
XII Dyanamic Memory
Allocation
41-42
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35
pf36
pf37
pf38
pf39
pf3a
pf3b
pf3c
pf3d
pf3e
pf3f
pf40
pf41
pf42
pf43
pf44
pf45
pf46
pf47
pf48
pf49
pf4a
pf4b
pf4c
pf4d
pf4e
pf4f
pf50
pf51
pf52
pf53
pf54
pf55
pf56
pf57
pf58
pf59
pf5a
pf5b
pf5c
pf5d
pf5e
pf5f
pf60
pf61
pf62
pf63
pf64

Partial preview of the text

Download C Programming: From Theory to Coding and more Study notes C programming in PDF only on Docsity!

CONTENTS

THEOReTICAL BASED

UNIT NO. CHAPTER NAME PAGE NO.

I Introduction to C 3- II Variables, Data types, Constants

III Operators and Expressions

IV Input and Output 18- V Control Statements 21- VI Arrays 28- VII Strings 31- VIII Functions 33- IX Pointers 36- X Structures and Unions 39- XI File Handling 40- XII Dyanamic Memory Allocation

CONTENTS

CODING BASED

- I Basic Programs 43- UNIT NO. CHAPTER NAME PAGE NO. - II Arrays 57- - III Loops 63- - IV Patterns 72- - V Arrays 80- - VI Strings 89-
  • VII Functions 97-
  • VIII Pointers 103- - IX Structures 107- - X File Handling 112- - XI Switch Case 116-
    • XII Matrix 123-

UNIT-I

Introduction to C

1. What is C language? Answer: C is a general-purpose, structured and high-performance programming language developed by Dennis Ritchie at Bell Laboratories in 1972. It is widely used for system programming, operating systems, embedded systems, and application development. C supports low-level memory manipulation along with high-level constructs, which makes it both powerful and flexible. Due to its efficiency, portability, and closer relation to hardware, C has become the foundation for many modern languages such as C++, Java and Python. 2. Why is C called a structured language? Answer: C is called a structured language because it allows a program to be divided into smaller, manageable units called functions. The structured approach improves readability, debugging, modification, and reusability of

code. It supports control structures like if-else, loops,
switch-case, which help in writing logically organized

programs. Structured programming avoids the use of “goto” and encourages top-down design, where a problem is solved by breaking it into sub-tasks.

3. Why is C called a middle-level language? Answer: C is called a middle-level language because it contains the features of both high-level and low-level languages.  As a high-level language , it supports functions, loops, arrays, and readability.  As a low-level language , it provides direct memory access using pointers, manipulation of hardware addresses, and efficient machine-level execution. This combination gives C the power of assembly language with the ease of a structured, high-level language. 4. Features of C language. Answer: Important features of C are: 1. Portability: C programs can run on different machines with little or no modification. 2. Efficiency: C produces fast and optimized machine code. 3. Structured Language: Programs are divided into functions for clarity and maintainability. 4. Rich Library: C supports many built-in functions.

code

7. What is source code and object code? Answer:Source Code: The original program written in a high-level language like C. It is saved with a “.c” extension.  Object Code: The machine-level output generated by the compiler. It is usually saved with “.obj” or “.o” extension. This code is later linked to form the executable file. 8. What is a token in C? Name the types of tokens. Answer: A token is the smallest individual unit or element of a C program. The C compiler reads and processes the program by breaking it into tokens. The main types of tokens are: 1. Keywords 2. Identifiers 3. Constants 4. Operators 5. Strings

6.Punctuators / Special symbols

  1. Variable names are case sensitive (age and Age are different). 3. What is a data type? Answer: A data type defines the type of data a variable can store and determines the amount of memory allocated to it. It also specifies the operations that can be performed on that data. Examples include int, float, char, double, etc. 4. Sizes of basic data types.
(These may vary slightly depending on compiler, but
standard sizes are:)

Answer:  char → 1 byte  int → 2 or 4 bytes  float → 4 bytes  double → 8 bytes  long int → 4 or 8 bytes These sizes help the programmer understand how much memory the program will use.

5. What is a constant? Types of constants. Answer: A constant is a fixed value that does not change during program execution. Constants provide reliability and prevent accidental modification of important values. Types of constants include:

  1. Integer constants: e.g., 10, -
  2. Floating-point constants: e.g., 3.14, -0.
  3. Character constants: e.g., 'a', '3', '\n'
  4. String constants: e.g., "Hello"
  5. Symbolic constants: Defined using #define 6. Difference between variable and constant. Answer: Variable Constant Value can change Value cannot change Declared using data type Declared using const or #define Stored in memory Symbolic constants may not use memory Example: int x = 10; Example: const int x = 10;

UNIT-III

Operators & Expressions

1. What is an operator? Give examples. Answer: An operator is a symbol that tells the compiler to perform a specific mathematical or logical operation on data. Examples: +, -, *, /, %, ==, &&, ||. 2. What are operands? Answer: Operands are the data or variables on which operators act. Example: In a + b, a and b are operands and + is the operator. 3. Types of operators in C. Answer: C supports several types of operators: 1. Arithmetic operators → + - * / % 2. Relational operators → < <= > >= == != 3. Logical operators → && ||! 4. Assignment operators → = += -= *= /= %= 5. Increment/decrement operators → ++ --

  1. Conditional/ternary operator → ?:
  2. Bitwise operators → & | ^ << >> ~
  3. Special operators → sizeof, comma operator , 4. Arithmetic operators with example. Answer: These operators perform basic mathematical operations. Example: If a = 10, b = 3, then  a + b = 13  a / b = 3 (integer division)  a % b = 1 (remainder) 5. Relational operators. Why are they used? Answer: Relational operators compare two values. They return either true (1) or false (0). Examples: <, >, <=, >=, ==, != They are mainly used in decision-making statements like if, while. 6. Logical operators with example. Answer: Logical operators combine multiple conditions.

9. What is the modulus operator? Where is it used? Answer: The modulus operator % gives the remainder after division. Used in:  Finding even/odd  Extracting digits  Working with cycles or periodic patterns 10. What is an expression? Answer: An expression is a combination of variables, constants, and operators that produce a value. Example: x = a + b * 5; 11. What is operator precedence? Answer: Operator precedence determines the order in which operators are evaluated in an expression. Example:

  • and / have higher precedence than + and -. So in a + b * c, multiplication is done first.

12. What is associativity? Answer: Associativity defines the direction in which an expression is evaluated when two operators have the same precedence. Most operators are left-to-right associative , except unary operators and assignment operators (right-to-left). 13. What is the size of operator (sizeof)? Answer: sizeof is a compile-time operator that returns the amount of memory (in bytes) used by a data type or variable. Example: sizeof(int) returns 2 or 4 bytes. 14. What is the conditional/ternary operator? Answer: The ternary operator ?: is a shorthand for if-else. Syntax: condition? expression1 : expression If condition is true → expression1 executes, else expression2 executes.

Typecasting is used when performing operations between different data types or when precise control over data conversion is required.

18. What is the sizeof operator? Answer: sizeof is a compile-time unary operator used to determine the memory size (in bytes) of a variable or data type. Example: sizeof(int); // typically 4 bytes It helps in memory management and writing portable code across different systems.

UNIT-IV

Input & Output in C

1. Purpose of printf() and scanf() printf()  printf() is a standard output function in C.  It is used to display text, variables, and results on the screen.  It uses format specifiers to print different types of data. scanf()  scanf() is a standard input function.  It is used to take input from the user through the keyboard.  It reads values and stores them into variables using address (&). 2. Format specifiers Format specifiers tell printf()/scanf() what type of data to read or print. Specifi er Meaning %d Integer (int) %f Float (for printf), read float in