C is a general-purpose programming language. Many of C’s important ideas come from the BCPL language developed by Martin Richards. On the contrary, C provides various types of data.
The data types of C programming language are characters, integers, and floating-point numbers of several sizes.
C is a relatively low level of language. C does not require any operations to work directly with complex objects, such as character strings, sets, lists, or arrays.
Like syntax of Java, PHP, JavaScript, and other languages are mainly based on C language. C++ is nearly a superset of C language (There are few programs that may compile in C, but not in C++).
Hello World Program in C
This program will print “Hello World” on the output screen of your compiler.
#include<stdio.h> int main() { printf("Hello World"); }
Output:
Hello World
Example of a C Program
This program will ask the user to input a number & print the same number on the output screen.
#include<stdio.h> int main() { int a; scanf("Please enter a number: %d",&a); printf("%d",a); }
Output:
Please enter a number: 5 5
Structure of a C Program
Inclusion of Header Files
In C programming language header files are like a dictionary of in-built functions. It is mandatory to include the header files in order to perform the required operation. <stdio.h> is the basic input/output header file that’s used by all the C program.
Syntax to include header files in C Program
#include <(header_file_name) .h>
Example to include header files in C Program
#include<stio.h>
Some of the C header files are:
- stdio.h – defines the basic functions of input and output
- stdlib.h – defines numerical conversion functions, pseudorandom network generator, memory allocation.
- string.h – Defines string processing functions
- stddef.h – Defines several useful types and macros.
- stdint.h – Defines the exact types of exact width.
- math.h – defines common math functions
Declaration of the Main Method
The next step of C is to declare the main () function.
The syntax for declaring the main method is:
int main () { }
Declaration of Variable
After the declaration of the main method, the declaration of the variable is done. In C, no variable can be used without a declaration. Also in C, variables must be declared before any function operation.
Syntax for declaring the variable:
int main() { int a; . .
Body
This applies to operations performed in functions. It can be anything like manipulation, search, sorting, printing and more.
Example:
int main() { int a; printf("%d", a); }
Return Statement
The return statement in C returns the function’s values. If the return type is void, then there will be no return statement. In any other case, there will be a return statement and the return value will be of the type of the specified return type.
Example:
int main() { int a; printf("%d", a); return 0; }