Skip to content
C Programming Syntax Guide
1. Basic Structure of a C Program
#include <stdio.h> int main() { printf("Hello, World!\n"); return 0; } 2. Data Types and Variables
int age = 25; float price = 19.99; char grade = 'A'; 3. Input and Output
printf("Enter your name: "); scanf("%s", name); 4. Control Structures
if (condition) { // code to execute if the condition is true } else { // code to execute if the condition is false } 5. Loops
for (int i = 0; i < 5; i++) { // code to repeat 5 times } 6. Functions
int add(int a, int b) { return a + b; } 7. Arrays
int numbers[5] = {1, 2, 3, 4, 5}; 8. Pointers
int *ptr; ptr = &age; 9. Structures
struct Person { char name[50]; int age; }; 10. File Handling
FILE *file = fopen("example.txt", "r"); if (file != NULL) { // code to read or write to the file fclose(file); } 11. Dynamic Memory Allocation
int *dynamicArray = (int *)malloc(5 * sizeof(int)); free(dynamicArray); 12. Preprocessor Directives
#define MAX_SIZE 100 13. Bitwise Operators
result = a & b; result = a | b; result = ~a; 14. Function Pointers
int (*operation)(int, int) = &add; int result = operation(5, 3);
0 Comment:
Post a Comment