0% found this document useful (0 votes)
2 views

C programming language

This document provides a concise overview of key concepts in the C programming language, including basic syntax, functions, pointers, arrays, structures, memory management, file I/O, error handling, preprocessor directives, and compiling and running programs. Each section includes definitions and examples to illustrate the concepts. It serves as a quick guide for understanding fundamental aspects of C programming.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

C programming language

This document provides a concise overview of key concepts in the C programming language, including basic syntax, functions, pointers, arrays, structures, memory management, file I/O, error handling, preprocessor directives, and compiling and running programs. Each section includes definitions and examples to illustrate the concepts. It serves as a quick guide for understanding fundamental aspects of C programming.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Ah, got it!

If you're looking for notes or a quick guide on the C programming language, here’s a brief
overview of key concepts:

1. Basic Syntax

 Variables & Data Types: C has several built-in data types, such as int, char, float, double, and
void.

 Operators: Arithmetic (+, -, *, /, %), relational (==, !=, <, >, <=, >=), logical (&&, ||, !), and
assignment (=, +=, -=, *=, /=).

 Control Flow: if, else, while, for, switch, break, continue.

2. Functions

 Functions are defined with a return type, name, and parameters (if any).

 Example:

 int add(int a, int b) {

 return a + b;

 }

3. Pointers

 Pointers store memory addresses, which are crucial for dynamic memory allocation and for
working with arrays or structures.

 Declaration: int *ptr;

 Dereferencing: *ptr to access the value at the pointer's address.

 Example:

 int a = 10;

 int *p = &a;

 printf("%d", *p); // Outputs 10

4. Arrays

 Arrays are used to store multiple values of the same type.

 Example:

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

5. Structures

 Structures allow you to group different data types together.

 Example:

 struct Person {

 char name[50];
 int age;

 };

6. Memory Management

 Functions like malloc(), calloc(), realloc(), and free() help manage dynamic memory
allocation.

 Example:

 int *arr = (int *)malloc(5 * sizeof(int)); // Allocate memory

 free(arr); // Free allocated memory

7. File I/O

 C provides functions for working with files: fopen(), fclose(), fread(), fwrite(), fprintf(),
fscanf().

 Example:

 FILE *f = fopen("file.txt", "r");

 char ch = fgetc(f);

 fclose(f);

8. Error Handling

 Commonly done using errno (for system errors) or manually through condition checks.

 Example:

 if (f == NULL) {

 printf("Error opening file.\n");

 }

9. Preprocessor Directives

 Directives like #include and #define are used to include libraries and define
constants/macros.

 Example:

 #define PI 3.14

10. Compiling and Running

 C programs are typically compiled using a compiler like gcc and executed from the command
line.

 Command to compile: gcc program.c -o program

 Command to run: ./program

Is there a specific area you want to dive deeper into? Let me know if you need more examples or
explanations!

You might also like