C Programming Notes
1. Primitive Data Types
Primitive data types are the basic building blocks in C:
- int: Integer values (e.g., int x = 10;)
- float: Single-precision decimal (e.g., float f = 3.14;)
- double: Double-precision decimal (e.g., double d = 3.14159;)
- char: Single character (e.g., char c = 'A';)
- void: No value (used for functions with no return value)
2. Structure
Structure is a user-defined data type that groups different types:
Example:
struct Student {
int id;
char name[20];
float marks;
};
struct Student s1 = {1, "Naresh", 85.5};
3. Self-Referential Structure
Structure that has a pointer to itself:
struct Node {
int data;
struct Node *next;
};
C Programming Notes
Used in Linked Lists, Trees, etc.
4. Pointers
Pointers store memory addresses:
int a = 5;
int *p = &a;
printf("%d", *p); // prints 5
printf("%p", p); // prints address of a
5. Matrix Multiplication (C Program)
Enter dimensions and values for two matrices.
Check if column1 == row2. Multiply using triple loop:
for(i=0; i<r1; i++)
for(j=0; j<c2; j++) {
mul[i][j] = 0;
for(k=0; k<c1; k++)
mul[i][j] += a[i][k] * b[k][j];