0% found this document useful (0 votes)
8 views6 pages

C Complete

This document provides comprehensive notes on C programming, covering its introduction, basic syntax, data types, operators, control structures, functions, arrays, pointers, structures, storage classes, file handling, dynamic memory allocation, preprocessor directives, and common built-in functions. It also discusses advantages and limitations of C, along with sample program snippets. The notes serve as a foundational guide for understanding and utilizing the C programming language.

Uploaded by

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

C Complete

This document provides comprehensive notes on C programming, covering its introduction, basic syntax, data types, operators, control structures, functions, arrays, pointers, structures, storage classes, file handling, dynamic memory allocation, preprocessor directives, and common built-in functions. It also discusses advantages and limitations of C, along with sample program snippets. The notes serve as a foundational guide for understanding and utilizing the C programming language.

Uploaded by

dihoncho.pro
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

📘 C Programming Complete Notes

📌 1. Introduction to C

 Developed by Dennis Ritchie in the 1970s.


 Structured, procedural, compiled language.
 Foundation for many modern languages like C++, Java, Python.

🔤 2. Basic Syntax
c
CopyEdit
#include <stdio.h>

int main() {
printf("Hello, World!");
return 0;
}

 #include <stdio.h>: Standard input/output header.


 main(): Entry point.
 printf: Output function.
 return 0: Ends program execution successfully.

🔠 3. Data Types

 Basic: int, char, float, double


 Derived: array, pointer, function, structure
 Void: Represents absence of value.
 Type modifiers: short, long, signed, unsigned

➕ 4. Operators

 Arithmetic: +, -, *, /, %
 Relational: ==, !=, >, <, >=, <=
 Logical: &&, ||, !
 Assignment: =, +=, -=, etc.
 Bitwise: &, |, ^, ~, <<, >>
 Increment/Decrement: ++, --

🔁 5. Control Structures

 Conditional:
o if, else, else if
o switch-case
 Loops:
o for, while, do-while
 Jump Statements:
o break, continue, goto, return

🧠 6. Functions
c
CopyEdit
int add(int a, int b) {
return a + b;
}

 Declaration, definition, and call.


 Parameters and return types.
 Recursion.
 void functions.
 Scope: local vs global variables.

📦 7. Arrays & Strings

 Arrays:

c
CopyEdit
int arr[5] = {1, 2, 3, 4, 5};

 Multidimensional Arrays:

c
CopyEdit
int matrix[3][3];

 Strings:
c
CopyEdit
char str[] = "Hello";

Use functions from <string.h> like strlen(), strcpy(), strcmp().

📌 8. Pointers
c
CopyEdit
int a = 10;
int *p = &a;

 * dereference operator
 & address-of operator
 Pointer arithmetic
 NULL pointer
 Pointers with arrays, functions, strings.
 Pointer to pointer (int **pp)

🧠 9. Structures & Unions


c
CopyEdit
struct Student {
int id;
char name[20];
};

 Group related variables.


 Nested structures.
 Array of structures.
 Union: Shared memory for variables.

🛠 10. Storage Classes

 auto (default for local variables)


 static (persistent across function calls)
 extern (used across files)
 register (store in CPU register if possible)
🧠 11. File Handling
c
CopyEdit
FILE *fp = fopen("file.txt", "r");
fgets(buffer, 100, fp);
fclose(fp);

 fopen(), fclose(), fscanf(), fprintf(), fgets(), fputs()


 Modes: "r", "w", "a", "rb", "wb"

🧠 12. Dynamic Memory Allocation


c
CopyEdit
int *p = (int*) malloc(sizeof(int));
free(p);

 malloc(), calloc(), realloc(), free()


 Located in <stdlib.h>

🧠 13. Preprocessor Directives

 #define constants/macros
 #include header files
 #ifdef, #ifndef, #endif, #undef

c
CopyEdit
#define PI 3.14

💡 14. Miscellaneous Concepts

 Command Line Arguments:

c
CopyEdit
int main(int argc, char *argv[]) { }

 Enum:

c
CopyEdit
enum week {Mon, Tue, Wed};
 Typedef:

c
CopyEdit
typedef int Integer;

🧠 15. Common Header Files

 <stdio.h>: Standard I/O


 <stdlib.h>: Memory, process control
 <string.h>: String manipulation
 <math.h>: Math functions
 <ctype.h>: Character type checking
 <time.h>: Date/time

🔄 16. Common Built-in Functions

 printf, scanf, gets, puts


 strlen, strcpy, strcmp, strcat
 malloc, calloc, free, realloc
 pow, sqrt, abs, rand, srand

🧠 17. Sample Program Snippets

 Factorial using recursion:

c
CopyEdit
int fact(int n) {
if(n <= 1) return 1;
else return n * fact(n - 1);
}

 Swap using pointers:

c
CopyEdit
void swap(int *a, int *b) {
int temp = *a;
*a = *b;
*b = temp;
}
🚀 18. Advantages of C

 Fast execution
 Low-level memory manipulation
 Portability
 Foundation for learning other languages

⚠️ 19. Limitations

 No object-oriented features
 No built-in memory safety
 Manual memory management

You might also like