C Language Introduction
C is a procedural programming language. It was developed by Dennis Ritchie in 1972. It was mainly developed as a system programming language to write Operating system.
The main features of C language include low-level access to memory, simple set of keywords, and clean style, these features make C language suitable for system programming like operating system or compiler development.
Many later languages have borrowed syntax/features directly or indirectly from C language. Like syntax of Java, PHP, JavaScript and many other languages is 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++).
C provides the fundamental control-flow constructions required for well-structured programs: statement grouping, decision making (if-else), selecting one of a set of possible values (switch), looping with the termination test at the top (while, for) or at the bottom (do), and early loop exit (break).
Functions may return values of basic types, structures, unions, or pointers. Any function may be called recursively. Local variables are typically ``automatic'', or created anew with each invocation. Function definitions may not be nested but variables may be declared in a block-structured fashion.
The functions of a C program may exist in separate source files that are compiled separately. Variables may be internal to a function, external but known only within a single source file, or visible to the entire program.
A Preprocessing step performs macro substitution on program text, inclusion of other source files, and conditional compilation.
C is a relatively low-level language. This characterisation is not pejorative; it simply means that C deals with the same sort of objects that most computers do, namely characters, numbers, and addresses. These may be combined and moved about with the arithmetic and logical operators implemented by real machines.
For more on C programming language theory – soon…
Beginning with C programming:
Compiler:
Before we start C programming, we need to have a compiler to compile and run/execute our programs. There are certain compilers like Codeblock ,DevC++,Visual C++ that can be used to start C/C++ with installing a compiler.
For Windows: There are many compilers available freely for compilation of C programs like Code Blocks and Dev-CPP. We strongly recommend Code Blocks.
For running Codeblock for c/c++ program click here
For running Codeblock for c/c++ program click here
Writing Your first program:
Output:
Easy programming
Line 1: # is to indicate that this line of code is preprocessed before passing to the compiler and the actual code after preprocessing does not include any line with # i.e the header file “stdio.h” got replace in place of #include <stdio.h> . These header files generally contain declaration of functions. We need stdio.h for the function printf() used in the program.
Line 2: In C, the execution typically begins with main() function. The void written in brackets indicates that the main doesn’t take any parameter. The int written before main indicates return type of main(). The value returned by main indicates status of program termination.
Line 3: Brackets [ { and } ] In C language, a pair of curly brackets define a scope and mainly used in functions and control statements like if, else, loops.
Line 4: printf() is a standard library function to print something on standard output screen/console. The semicolon at the end of printf indicates line termination. In C language, semicolon is always used to indicate end of statement.
Line 5: The return statement returns the value from main(). The returned value may be used by operating system to know termination status of your program. The value 0 typically means successful termination.
No comments:
Post a Comment
Thank you for your Time. Keep Learning