Introduction
C Language is said to be the mother of programming language, Denis Ritchie is the original inventor of it. He wanted to develop a general purpose Operating System, but no such programming language was there.
Therefore, Dennis Ritchie (1941-2011) has decided to develop general purpose programming language and he invented C language. Later he develop Unix operating system using C language.
Features of C Language
- Procedural language
- Structured language
- Easy to learn (simple)
- Fast & Efficient
- Modularity
- Rich Libraries (inbuilt functions)
- Easy to extend
- Machine Independent or portable (unlike assembly)
- It can handle low-level activities
Few facts about C Language
- C was invented to write an operating system called UNIX.
- C is a successor of B language which was introduced around the early 1970s.
- The language was formalized in 1988 by the American National Standard Institute (ANSI).
- Today’s C is the most widely used and popular System Programming Language.
- The UNIX OS was totally written in C.
- Today’s most popular Linux and RDBMS MySQL have been written in C.
C character set
- Letters
- Alphabet : Uppercase A…Z Lowercase a…z
- Digits
- All decimal digits: 0…9
- Special Characters
- : ; ! ” # % & ‘ ( ) * + , – . / : ; < = > ? [ \ ] ^ _ { | }
- White Spaces
- Blank Space, Horizontal tab, Carriage return, New line, form feed
Keywords or Reserved words → 32
auto | break | case | char |
const | continue | default | do |
double | else | enum | extern |
float | for | goto | if |
int | long | register | return |
short | signed | sizeof | static |
struct | switch | typedef | union |
unsigned | void | volatile | while |
C Tokens → smallest unit in a ‘C’ program
- Keywords
- Constants
- Strings
- Identifiers & Variables
- Operators
Main Function
- Main function -> Starting point of a C program
- Pair of parenthesis -> to indicate the function
- Open Curley -> Starting of main function (brace)
- Close Curley -> Ending of main function (brace)
- printf function to generate output
- String arguments to printf function for output
- Body of main function
What is #Include ?
// syntax
# include <header_file_name.h>
// example
# include <stdio.h>
- The #include is also known pre-processor directive.
- It is used to include header files (library functions) to a C program.
- The #include is the directive that instructs the compiler to find the file <filename.h” (<stdio.h> for example) and include in the current source file.
- stdio.h means “standard input and output” and “.h” means it is a header file rather than C source file which have “.c” extension.
- List of Headers files
What is Comment ?
- Comments provide clearness to the source code allowing others to better understand code.
- Comments in source code are not executed as part of the program.
- Comments can be placed anywhere in the program.
- Single Line Comments
- Create comments for single line.
- begins with // (double slash).
- Multiline Comments
- Comments are placed within /* and */ character sequences and may span any number of lines.
Single line comments
# include <stdio.h> // includes the stdio.h file
void main()
{
// start of main {
// body of main
printf ("www.raviroza.com");
// above will output the text
// end of main with }
}
Multiline comments
/*
Welcome to the tutorial of C Language
Author : Ravi R Oza
www.raviroza.com
*/
What is Variable ?
- Variable is data name that stores a value of a specific type.
- Each variable has a specific type such as int, chat, float or double.
Data Types in C Language
Data Type | Description | Memory |
int | Integer quantity | 2 bytes |
chat | Single character | 1 byte |
float | Floating point number | 4 bytes |
double | Double-precision floating point number | 8 bytes |
Rules for declaring Variables
No. | Rule |
1 | Variables name must start with a lowercase later (alphabet) or underscore (_). |
2 | No spaces are allowed in variables names. |
3 | Except underscore (_), no other symbol are allowed in variable names. |
4 | No keywords (reserved words) are allowed as variable names. |
Input & Output in C
In C language there library function to perform Input & Output, lets discuss them. printf() function -> output/display text or variables in console screen (monitor). scanf() function -> input/scan values/variables from user using standard input (key board)
Output in C : printf() function
Example :
#include <stdio.h>
void main()
{
int age = 5;
float weight = 930.25;
double int_rate = 8.09;
char gender = 'm'
// Displays the text to screen
printf("C Programming");
// Display/output int variable
printf("\n\nAge is = %d", age);
// Display/output float variable
printf("\nWeight is = %f\n", weight);
// Display/output double variable
printf("\nInterest Rate is = %lf", int_rate);
// Display/output char variable
printf("\nGender is = %c", gender);
getch();
}