0% found this document useful (0 votes)
4 views5 pages

C Programming - Notes

The document provides concise notes on C programming, covering its introduction, structure, data types, operators, control statements, functions, arrays, pointers, structures, file handling, dynamic memory allocation, preprocessor directives, advantages, common errors, applications, and its future importance. It highlights C's efficiency, portability, and foundational role in computing and various applications. The notes are structured for easy revision and class use.

Uploaded by

kevin
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views5 pages

C Programming - Notes

The document provides concise notes on C programming, covering its introduction, structure, data types, operators, control statements, functions, arrays, pointers, structures, file handling, dynamic memory allocation, preprocessor directives, advantages, common errors, applications, and its future importance. It highlights C's efficiency, portability, and foundational role in computing and various applications. The notes are structured for easy revision and class use.

Uploaded by

kevin
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Perfect 👍

Here’s the point-wise, text-based “C Programming – Concise Notes” (structured like student
notes).
This version is ideal for class use or revision and matches the 50-page style in content density.

🧠 C Programming – Concise Notes

1. Introduction to C
 C is a general-purpose, procedural programming language developed by Dennis Ritchie
at Bell Labs (1972).
 It is widely used for system programming, embedded systems, and application
software.
 Provides low-level memory access and fast execution.
 Serves as the foundation for languages like C++, Java, and Python.
 Programs are written as functions with a main function controlling execution flow.
 Portable and efficient, hence used in compilers, OS kernels, and drivers.

2. Structure of a C Program
 Documentation Section → Describes program purpose (comments).
 Preprocessor Section → Includes header files (#include <stdio.h>).
 Definition Section → Defines constants using #define.
 Global Declaration → Declares global variables and functions.
 Main Function → Entry point of execution.
 Subprograms → User-defined functions for modularity.

Example:

#include <stdio.h>
int main() {
printf("Hello, World!");
return 0;
}

3. Data Types and Variables


 Basic Types: int, float, char, double.
 Derived Types: Arrays, Structures, Pointers, Functions.
 Enumeration: enum used for symbolic constants.
 Void Type: Indicates no return or no parameter.
 Storage Classes:
o auto – default for local variables.
o register – stored in CPU for faster access.
o static – retains value between function calls.
o extern – used for global variables across files.

4. Operators in C
 Arithmetic: +, -, *, /, %
 Relational: ==, !=, <, >, <=, >=
 Logical: &&, ||, !
 Assignment: =, +=, -=, *=
 Bitwise: &, |, ^, <<, >>
 Special Operators: sizeof, ?:, comma (,)

5. Control Statements
 Decision Making:
o if, if-else, nested if, switch.
 Looping:
o for, while, do-while.
 Jump Statements:
o break, continue, goto, return.

Example:

for (int i = 0; i < 5; i++) {


printf("%d ", i);
}

6. Functions in C
 Functions are reusable blocks performing specific tasks.
 Syntax:
 return_type function_name(parameters) {
 // code
 }
 Advantages:
o Code reusability
o Easier debugging
o Modular programming
 Types: Library functions (printf(), scanf()), User-defined functions.
 Supports recursion.

7. Arrays and Strings


 Array: Collection of similar data types.
o Syntax: int arr[5];
 Multidimensional Arrays: Used for tables or matrices.
 String: Array of characters ending with '\0'.
o Example: char name[20] = "Kevin";
 Common String Functions:
o strcpy(), strlen(), strcmp(), strcat().

8. Pointers
 Pointer: Variable that stores the address of another variable.
 Declared using * (e.g., int *ptr;).
 Address Operator (&): Returns variable’s address.
 Dereference Operator (*): Accesses value stored at address.
 Uses: Dynamic memory, arrays, strings, function arguments.
 NULL Pointer: Points to no valid memory.

9. Structures and Unions


 Structure: Collection of variables of different data types.
 struct Student {
 int id;
 char name[50];
 };
 Union: Shares memory for all members; efficient but stores one value at a time.
 Nested Structures: Structure inside another structure.

10. File Handling


 Files store data permanently on disk.
 Functions:
o fopen(), fclose(), fprintf(), fscanf(), fgets(), fputs().
 File Modes:
o "r" – read
o "w" – write
o "a" – append
 File Pointer: FILE *fp;

11. Dynamic Memory Allocation


 Managed at runtime using <stdlib.h>.
 Functions:
o malloc() – allocate memory block.
o calloc() – allocate multiple blocks.
o realloc() – resize block.
o free() – release memory.
 Prevents wastage and enables flexible data structures.

12. Preprocessor Directives


 Processed before compilation.
 Common Directives:
o #include – include files
o #define – macros
o #ifdef / #ifndef – conditional compilation
 Example:
 #define PI 3.14

13. Advantages of C
 Fast and efficient.
 Portable and widely available.
 Easy to learn and structured.
 Ideal for embedded and system-level software.

14. Common Errors


 Syntax Errors: Missing semicolons, braces.
 Logical Errors: Wrong logic.
 Runtime Errors: Division by zero, invalid pointer.
 Linker Errors: Undefined functions or libraries.

15. Applications
 Operating Systems (UNIX, Linux).
 Embedded systems and IoT devices.
 Compiler and kernel development.
 Network drivers and firmware.
 Game engines and simulations.

16. Future & Importance


 C remains the foundation of computing.
 Core for IoT, microcontrollers, robotics, and AI hardware.
 Still in demand due to performance and portability.

You might also like