Learn coding with amol
Hello my name is amol sharma or vineet and this is my fifth part of learn coding with amol and in this part we are learning c language.
PART-5 c language
Let's Startπ» Complete C Language Guide
This guide covers the fundamentals of C programming with explanations and copyable examples.
1. Hello World
Basic structure of a C program.
#include <stdio.h>
int main() {
printf("Hello, World!");
return 0;
}
2. Variables and Data Types
Variables store data values. C has types like int, float, char.
int age = 13;
float pi = 3.14;
char grade = 'A';
3. Input and Output
Use scanf to get user input.
int num;
printf("Enter a number: ");
scanf("%d", &num);
printf("You entered: %d", num);
4. if / else
Conditionally execute code blocks.
int x = 10;
if (x > 5) {
printf("Greater than 5");
} else {
printf("5 or less");
}
5. Loops (for, while)
Repeat code using loops.
for (int i = 0; i < 5; i++) {
printf("%d\\n", i);
}
int j = 0;
while (j < 5) {
printf("%d\\n", j);
j++;
}
6. Functions
Functions help organize reusable code.
void greet() {
printf("Hello from a function!");
}
int main() {
greet();
return 0;
}
7. Arrays
Arrays store multiple values of the same type.
int numbers[3] = {1, 2, 3};
printf("%d", numbers[0]);
8. Pointers
Variables that store memory addresses.
int x = 10;
int *ptr = &x;
printf("%d", *ptr);
9. Structures
User-defined data types to group variables.
struct Person {
char name[20];
int age;
};
struct Person p1 = {"Amol", 13};
printf("%s", p1.name);
10. File Handling
Read and write files using FILE pointers.
FILE *f = fopen("data.txt", "w");
fprintf(f, "Hello, File!");
fclose(f);

Comments
Post a Comment