0% found this document useful (0 votes)
9 views4 pages

Detailed C Programming Notes

The document provides detailed academic notes on C programming, covering fundamentals such as program structure, data types, operators, control statements, arrays, strings, functions, pointers, and dynamic memory allocation. It emphasizes key topics including loops, conditional statements, string handling, recursion, and memory management. The notes serve as a comprehensive guide for understanding the essential components of C programming.

Uploaded by

ashmit6666
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)
9 views4 pages

Detailed C Programming Notes

The document provides detailed academic notes on C programming, covering fundamentals such as program structure, data types, operators, control statements, arrays, strings, functions, pointers, and dynamic memory allocation. It emphasizes key topics including loops, conditional statements, string handling, recursion, and memory management. The notes serve as a comprehensive guide for understanding the essential components of C programming.

Uploaded by

ashmit6666
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

C Programming – Detailed Academic Notes

Unit I – Basics of C (Fundamentals)

1. Structure of a C Program
Every C program starts with preprocessor directives like #include and includes the main() function
where program execution begins. It generally follows this structure:
#include <stdio.h>
int main() {
printf("Hello, World!");
return 0;
}

2. Data Types and Variables


C provides several data types: int, float, char, double. Variables are named memory locations used to
store data. For example:
int age = 20;
float price = 99.5;
char grade = 'A';

3. Operators
Operators perform operations on data. Examples include: - Arithmetic: +, -, *, /, % - Relational: ==, !=, >,
<, >=, <= - Logical: &&, ||, ! - Unary: ++, --

4. Operator Precedence and Associativity


Determines the order in which operations are performed. Multiplication and division are evaluated
before addition and subtraction. Parentheses can be used to change precedence.

5. Input and Output Functions


C uses printf() for output and scanf() for input. Both rely on format specifiers such as %d, %f, %c, and
%s.
int age;
printf("Enter age: ");
scanf("%d", &age);
printf("Age = %d", age);

6. Type Declaration and Format Specifiers


Type declaration defines the variable’s data type, and format specifiers determine how data is read or
printed.
Unit II – Control Statements

1. If-else and Nested If


if (marks >= 50)
printf("Pass");
else
printf("Fail");

2. Loops (for, while, do-while)


for (int i = 1; i <= 5; i++) {
printf("%d ", i);
}

3. Switch-case Statement
switch(choice) {
case 1: printf("Start"); break;
case 2: printf("Stop"); break;
default: printf("Invalid");
}

4. Break, Continue, and Goto


Break exits from a loop, continue skips the rest of the current iteration, and goto jumps to a labeled
statement.

5. Ternary Operator
result = (a > b) ? a : b;
Unit III – Arrays and Strings

1. 1D and 2D Arrays
int arr[5] = {1, 2, 3, 4, 5};
int matrix[2][3] = {{1,2,3},{4,5,6}};

2. Accessing Elements
Elements are accessed using index notation, starting from 0. Example: arr[2] refers to the third element.

3. String Handling Functions


Common string functions include strlen(), strcpy(), strcmp(), and strcat(). Example:
char s1[20] = "Hello";
char s2[20] = "World";
strcat(s1, s2);
printf("%s", s1);

4. Character Arrays vs Strings


A string is a character array terminated with a null character '\0'.

5. Array Overflow
Occurs when accessing elements outside the declared bounds, which leads to undefined behavior.

6. Memory Concept
Arrays occupy contiguous memory locations in RAM.
Unit IV – Functions

1. Function Declaration, Definition, and Calling


int sum(int a, int b);
int main() {
printf("%d", sum(3,4));
}
int sum(int a, int b) {
return a + b;
}

2. Call by Value vs Call by Reference


void swap(int *a, int *b) {
int temp = *a;
*a = *b;
*b = temp;
}

3. Passing Arrays to Functions


void display(int arr[], int n) {
for(int i=0;i<n;i++)
printf("%d ", arr[i]);
}

4. Recursion
int fact(int n) {
if (n==0) return 1;
else return n * fact(n-1);
}
Unit V – Pointers and Dynamic Memory Allocation

1. Pointers
int x = 10;
int *p = &x;
printf("%d", *p);

2. Pointer Arithmetic
Pointer arithmetic includes operations like increment (p++) and decrement (p--) which move the pointer
to next/previous memory locations.

3. Pointers with Arrays and Strings


int arr[3] = {10, 20, 30};
int *p = arr;
printf("%d", *(p+1));

4. Dynamic Memory Allocation


int *ptr = (int*) malloc(5 * sizeof(int));
free(ptr);

5. Static vs Dynamic Memory


Static memory is fixed during compile time, while dynamic memory is allocated during runtime using
library functions.
Summary – Top 10 Super Important Topics

1. Structure of C program
2. Data types and operators
3. Loops (for, while, do-while)
4. If-else and switch
5. 1D and 2D arrays
6. String functions (strlen, strcpy, etc.)
7. Functions – call by value/reference
8. Recursion
9. Pointers and arrays
10. Dynamic Memory Allocation (malloc, calloc, free)

You might also like