C Notes

C
DSA
Software Engineering
Software Architecture
Operating System
Big Data
Data Mining and Warehousing
TOC
Ada
CPP
DBMS

All Topics (20)

  • 1. Why should we learn a programming language?
  • 2. Why are we starting our programming journey with C language?
  • 3. History of C Language
  • 4. Who created C language?
  • 5. Where was C language developed?
  • 6. When was C language developed?
  • 7. Why is C still popular even after many years?
  • 8. First C Program Example
  • 9. What is a Header File & Why Do We Use Header Files in C?
  • 10. What is stdio.h Header File in C?
  • 11. What is conio.h in C and Why Do We Use It?
  • 12. Why is # symbol used in C language? What is #include?
  • 13. What is a Function in C?
  • 14. What is Compilation of Code in C?
  • 15. Data Types in C (Size, Format Specifier & Range)
  • 16. Understanding ASCII in C Programming
  • 17. Understanding Float, Double, and Long Double in C
  • 18. What Are Operators in C?
  • 19. Type Casting vs Type Conversion in C/C++
  • 20. Type Promotion in C Programming

6. When was C language developed?

C language was developed in 1972.

7. Why is C still popular even after many years?

C is still popular because:

a. Versatility (All-rounder Language)

C can be used to develop:

b. Fast and Efficient

  • C programs run very fast.

  • It gives direct access to memory.

c. Foundation Language

  • Many modern languages like:

    • C++

    • Java

    • Python
      are influenced by C.

d. Used in Important Systems

 That’s why C is still called an “All-rounder” and “Mother language of many languages.”

8. First C Program Example

#include <stdio.h>   // Standard Input Output header file
#include <conio.h>   // Console Input Output header file (for getch(), clrscr(), etc.)

void main() {
   // This is the main function from where execution starts
   printf("Hello User");  // Prints message on the screen
   getch();        // Waits for user to press a key
}

9. What is a Header File & Why Do We Use Header Files in C?

header file in C programming is a file that contains predefined functions, macros, constants, and type definitions that you can use in your program. Header files usually have the extension .h, for example:

  • stdio.h – for input/output functions like printf() and scanf().
  • math.h – for mathematical functions like sqrt(), pow(), sin(), and cos().
  • conio.h – for console input/output functions like getch() and clrscr().

Think of a header file as a toolbox for C programmers. Instead of writing all the code from scratch, you can include these “tools” in your program to save time and effort.

Why Do We Use Header Files in C?

Including header files in C programming is essential for several reasons:

  1. Access Predefined Functions
    Header files contain functions that are already written and tested. For example, without including stdio.h, you cannot use printf() or scanf() in your program.
  2. Simplify Programming
    Header files allow you to write code faster because you don’t need to reinvent the wheel. All standard functions are available at your fingertips.
  3. Avoid Errors
    When you include a header file, the compiler knows the function prototypes (what arguments they take and what value they return). This prevents compilation errors.
  4. Code Reusability
    Header files promote modular programming. You can write reusable functions in separate header files and include them in multiple programs.
  5. Better Organization
    Large programs can be split into multiple header files to keep the code clean, organized, and easier to maintain.

When Should You Include a Header File?

You should include a header file whenever your program uses functions, constants, or types that are defined outside your program. Some common examples include:

Header File Functionality Example
stdio.h printf(), scanf()
math.h sqrt(), pow(), sin(), cos()
conio.h getch(), clrscr()
string.h strcpy(), strlen(), strcmp()

Syntax to include a header file:

#include <headerfile.h>

Example: Simple C Program Using a Header File

#include <stdio.h> // Standard input/output functions

int main() {
printf("Hello, User! Welcome to C Programming.\n");
return 0;
}

Here:

  • #include <stdio.h> allows the program to use printf().
  • Without including this header, the compiler would not recognize printf() and give an error.

10. What is stdio.h Header File in C?

In C programming, the stdio.h header file is one of the most important and widely used header files. The term stdio stands for Standard Input Output, which basically means it allows your program to take input from the user (keyboard) and display output on the screen (monitor).

Key Functions of stdio.h

The stdio.h header file provides functions that handle essential input and output operations in C. The most commonly used functions include:

  1. printf() – This function is used for output, i.e., displaying text, variables, or results on the screen.

     
    printf("Hello, World!\n");
  2. scanf() – This function is used for input, i.e., accepting data from the user via the keyboard.

     
    int age;
    scanf("%d", &age);

Why is stdio.h Important?

  • Essential for Almost Every Program:
    Almost every C program involves input and output, making stdio.h necessary for nearly all projects.
  • Simplifies Programming:
    Without stdio.h, programmers would have to write complex code to handle keyboard input and screen output manually.
  • Standardized Functions:
    Functions like printf() and scanf() are predefined, tested, and optimized, making coding faster and error-free.

Example: Using stdio.h

#include <stdio.h> // Standard Input/Output header file

int main() {
  int age;
  printf("Enter your age: "); // Output
  scanf("%d", &age); // Input
  printf("You are %d years old.\n", age); // Output
  return 0;
}
 

Explanation:

  1. #include <stdio.h> → Includes standard input/output functions.
  2. printf() → Displays a message on the screen.
  3. scanf() → Reads input from the user.
Page 2 of 4