Basic of C Programming

 Introduction to C Programming:

  • Developed by Dennis Ritchie in 1972 at Bell Labs.
  • Middle-level programming language.
  • Known for its simplicity and efficiency.
  • Widely used for system/software development and embedded systems.

Basic Structure of a C Program:

c
#include <stdio.h> int main() { // Code goes here return 0; }
  • #include <stdio.h>: Inclusion of standard input-output library.
  • int main() { }: Main function, entry point of a C program.

Data Types and Variables:

  • Data Types:

    • int: Integer (4 bytes).
    • float: Floating-point number (4 bytes).
    • double: Double-precision floating-point number (8 bytes).
    • char: Character (1 byte).
  • Variables:

    • A name given to a storage area in the program.
    • Example: int age = 25;

Operators:

  • Arithmetic Operators: +, -, *, /, %.
  • Relational Operators: ==, !=, <, >, <=, >=.
  • Logical Operators: && (AND), || (OR), ! (NOT).

Control Structures:

  • Conditional Statements:
    • if: Executes a block of code if a condition is true.
    • else if: Additional condition to be checked.
    • else: Executes if none of the above conditions are true.
c
if (condition) { // Code to be executed if condition is true } else if (anotherCondition) { // Code to be executed if anotherCondition is true } else { // Code to be executed if no conditions are true }
  • Loops:
    • for: Executes a block of code a specific number of times.
    • while: Executes a block of code as long as a condition is true.
    • do-while: Similar to while loop, but guarantees the code inside the loop is executed at least once.

Functions:

  • Block of code that performs a specific task.
  • Can take parameters and return values.
  • Example:
c
int add(int a, int b) { return a + b; }

Arrays:

  • Collection of elements of the same data type.
  • Accessed using index (starting from 0).
  • Example:
c
int numbers[5] = {1, 2, 3, 4, 5};

Pointers:

  • Variables that store memory addresses.
  • Used for dynamic memory allocation and manipulation.
  • Example:
c
int num = 10; int *ptr = &num; // ptr stores the address of num

Structures:

  • User-defined data type that can hold variables of different data types.
  • Example:
c
struct Person { char name[50]; int age; };

File Handling:

  • Operations related to reading from and writing to files.
  • fopen(), fclose(), fprintf(), fscanf(), etc.

Conclusion: C programming provides a solid foundation for understanding computer programming concepts. Mastering these basics is crucial for building more complex applications and delving into advanced topics like algorithms and data structures. Regular practice and hands-on coding are essential to becoming proficient in C programming.

Comments

Popular posts from this blog

Flowchart and Algorithm in C Language

Operators in C Language

Limitation,Advantages and Disadvantages of Flowchart and Algorithm