What is C language - Structure and syntax of C language
Learn what is C language? Structure and syntax of C language. C is a general-purpose, high-level language that was originally developed by Dennis M.
C is a general-purpose, high-level language that was originally developed by Dennis M. Ritchie to develop the UNIX operating system at Bell Labs. C was originally first implemented on the DEC-PDP-11 Computer in 1972. In 1978, Brain Kernighan and Dennis Ritchie produced the first publicly available description of C, now known as the K&R standard. The UNIX operating system, the C compiler, and essentially all UNIX application programs have been written in C.
C Language has now become a widely used professional language for various reasons:-
- Easy to learn
- Structured language
- It produces efficient programs.
- It can handle low-level activities
- It can be compiled on a variety of computer platforms.
Facts about C
- 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).
- The UNIX OS was totally written in C.
- Today C is the most widely used and popular System Programming Language.
- Most of the state-of-the-art software has been implemented using C.
- Today's most popular Linux OS and RDBMS MySQL have been written in C.
Why use C
C was initially used for system development work, particularly the programs that make-up the operating system. C was adopted as a system development language because it produces code that runs nearly as fast as the code written in assembly language. Some examples of the use of C might be:-
- Operating Systems
- Language Compilers
- Assemblers.
- Text Editors.
- Print Spoolers
- Network Drivers
- Modern programs
- Database
- Language interpreters
- Utilities
C Programs
A c program can vary from 3 lines to millions of lines and it should be written into one or more text files with extension “.c”; for example, hello.c. You use “vi”, “vim” or any other text editor to write your C program into a file.
C program Structure
Basically, a C program involves the following section:-
- Documentations
- Pre-processor Statements
- Global Declarations
- The main () function
- Local Declarations
- Program statements and Expressions
- User-defined Functions
#include
#include
Void Main()
{
/*first C program */
Print("Hello World")
Return;
}
Program Output:
Hello World!
_
Or in different way:
#include
int main()
{
/*first C program */
Printf(“HELLO, WORLD!\n”);
Return 0;
}
Let’s look into various parts of the above C program
/*comments*/- : ( Comments are a way of explaining what makes a program. Comments are ignored by the compiler and used by others to understand the code. )
"include<stdio.h> : (stdio is standard for input/output, this allows us to use some commands which include s header file called stdio.h )
int/void main(): int/void is a return, which will be explained in a while.
main() The main() : The main() is the main function where program execution begins. Every C program must contain only one main function.
Braces: Two curly brackets "{...}" are used to group all statements together.
Printf() return 0: It is a function in C, which prints text on the screen. At the end of the main function return value 0.
Basic Syntax of C
Semicolons:-
In a C program, the semicolon is a statement terminator. That is, each individual statement must be ended with a semicolon. It indicates the end of one logical entity.
Given below are two different statements:-
printf("HELLO,WORLD!\n")
return 0;
Identifiers:
A "C" identifier is a name used to identify a variable, function, or any other user-defined item. An identifier starts with A to Z, a to z an underscore '_' followed by zero or more letters, underscores, and digits ( 0 to 9 ). C does not allow punctuation characters such as @, &, and % within identifiers. C is a case-sensitive programming language. Thus, Manpower and manpower are two different identifiers in C.
Here are some examples of Acceptable identifiers:-
emp_name a_123
myname50 _temp j a23b9 retVal