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

C Programming Language

C Programming Language

Uploaded by

youssefbouh2
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)
3 views4 pages

C Programming Language

C Programming Language

Uploaded by

youssefbouh2
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/ 4

C Programming Language: Foundations and

Essentials
1. Introduction
• C is a general-purpose, procedural programming language created in 1972 by Dennis
Ritchie at Bell Labs.
• Key features:
o Low-level memory access
o High performance and efficiency
o Portability across systems
o Foundation for many modern languages (C++, C#, Java)

2. Basic Syntax
#include <stdio.h>

int main() {
printf("Hello, C!\n");
return 0;
}

• Functions: main() is the entry point


• Statements end with ;
• Comments: // for single line, /* */ for multi-line

3. Data Types & Variables


• Basic types: int, char, float, double
• Modifiers: short, long, unsigned, signed
• Example:

int age = 25;


char grade = 'A';
float height = 5.9;

4. Operators
• Arithmetic: + - * / %

Confidential – Oracle Internal


• Relational: == != > < >= <=
• Logical: && || !
• Assignment: = += -= *= /= %=

5. Control Flow
• If-Else

if (age > 18) {


printf("Adult\n");
} else {
printf("Minor\n");
}

• Switch

switch (grade) {
case 'A': printf("Excellent"); break;
case 'B': printf("Good"); break;
default: printf("Other");
}

• Loops

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


while(condition) { ... }
do { ... } while(condition);

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

int main() {
int result = add(5, 3);
printf("%d\n", result);
return 0;
}

• Functions allow code reuse


• Can return values or be void

7. Arrays & Pointers

Confidential – Oracle Internal


• Arrays

int numbers[5] = {1, 2, 3, 4, 5};


printf("%d\n", numbers[0]);

• Pointers

int x = 10;
int *ptr = &x;
printf("%d\n", *ptr); // 10

• Memory management with malloc and free

8. Structures
struct Person {
char name[50];
int age;
};

struct Person p1 = {"Alice", 25};


printf("%s\n", p1.name);

• Group different types together


• Basis for more complex data structures

9. File I/O
#include <stdio.h>

FILE *fp = fopen("file.txt", "w");


fprintf(fp, "Hello, file!\n");
fclose(fp);

• Open, read, write, and close files using FILE*


• Modes: "r", "w", "a"

10. Advanced Tips


• Always manage memory manually with care
• Use const to prevent unwanted changes
• Learn pointer arithmetic for efficiency

Confidential – Oracle Internal


• Master struct and typedef for readable code

11. Resources
• Official C Reference: https://en.cppreference.com/w/c
• Books: The C Programming Language by Kernighan & Ritchie
• Practice: HackerRank, LeetCode, Codeforces

Confidential – Oracle Internal

You might also like