C Language Introduction
C may be a procedural artificial language. it absolutely was at the start developed by Dennis Ritchie between 1969 and 1973. it absolutely was in the main developed as a system artificial language to jot down OS. the most options of C language embody low-level access to memory, straightforward set of keywords, and clean vogue, these options create C language appropriate for system programming like OS or compiler development.
Many later languages have borrowed syntax/features directly or indirectly from C language. Like syntax of Java, PHP, JavaScript and lots of alternative languages is principally supported C language. C++ is sort of a superset of C language (There area unit few programs that will compile in C, however not in C++).
Beginning with C programming:
Structure of a C program
After the on top of discussion, we are able to formally assess the structure of a C program. By structure, it's meant that any program will be written during this structure solely. Writing a C program in the other structure can therefore result in a Compilation Error.
Header Files Inclusion: the primary and foremost element is that the inclusion of the Header files in an exceedingly C program.
A header file may be a file with extension .h that contains C operate declarations and macro definitions to be shared between many supply files.
Some of C Header files
stddef.h – Defines several useful types and macros.
stdint.h – Defines exact width integer types.
stdio.h – Defines core input and output functions
stdlib.h – Defines numeric conversion functions, pseudo-random network generator, memory allocation
string.h – Defines string handling functions
math.h – Defines common mathematical functions
Syntax to include a header file in C:
#include <(header_file_name).h>
Main Method Declaration: The next part of a C program is to declare the main() function. The syntax to declare the main function is:
Syntax to Declare main method:
int main()
{}
Variable Declaration: subsequent a part of any program is that the variable declaration. It refers to the variables that area unit to be utilized in the operate. Please note that in program, no variable may be used while not being declared. conjointly in an exceedingly program, the variables area unit to be declared before any operation within the operate.
Example:
int main()
{
int a;
.
.
Body: Body of a operate in program, refers to the operations that area unit performed within the functions. It is something like manipulations, searching, sorting, printing, etc.
Example:
int main()
{
int a;
printf("%d", a);
.
.
Return Statement: The last half in any programme is that the come statement. The come statement refers to the returning of the values from a operate. This come statement and come worth depend on the return-type of the operate. as an example, if the come kind is void, then there'll be no come statement. In the other case, there'll be a come statement and therefore the come worth are of the sort of the required return-type.
Example:
int main()
{
int a;
printf("%d", a);
return 0;
}
#include <stdio.h>
int main(void)
{
printf("GeeksQuiz");
return 0;
}
Let us analyze the command by line.
Line 1: [ #include ] during a C program, all lines that begin with # square measure processed by preprocessor that may be a program invoked by the compiler. during a} very basic term, preprocessor takes a C program and produces another C program. The created program has no lines beginning with #, all such lines square measure processed by the preprocessor. within the on top of example, preprocessor copies the preprocessed code of stdio.h to our file. The .h files square measure referred to as header files in C. These header files typically contain declaration of functions. we'd like stdio.h for the operate printf() employed in the program.
Line two [ int main(void) ] There should to be start line from wherever execution of compiled C program begins. In C, the execution usually begins with initial line of main(). The void written in brackets indicates that the most doesn’t take any parameter (See this for additional details). main() are often written to require parameters conjointly. we'll be covering that in future posts.
The int written before main indicates come back style of main(). the worth came by main indicates standing of program termination. See this post for additional details on come back sort.
Line three and 6: [ ] In C language, a try of frizzy brackets outline a scope and primarily employed in functions and management statements like if, else, loops. All functions should begin and finish with frizzy brackets.
Line four [ printf(“Sayed”); ] printf() may be a commonplace library operate to print one thing on commonplace output. The punctuation mark at the top of printf indicates line termination. In C, punctuation mark is often wont to indicate finish of statement.
Line five [ come back 0; ] The come back statement returns the worth from main(). The came worth could also be utilized by package to grasp termination standing of your program. the worth zero usually suggests that no-hit termination.
Linux: For UNIX operating system, gcc comes bundled with the UNIX operating system, Code Blocks may also be used with UNIX operating system.
Please write comments if you discover something incorrect, otherwise you wish to share additional data regarding the subject mentioned on top of
that's a great larning post
ReplyDeletethank you
Delete