Basic Syntax in C
We need to know some basic and important syntax before we start learning something more about C , it will help us in coding C programs without any advance knowledge for our upcoming tutorials. Here are some very basic syntax in C which we need to know for writing a C program properly.
For Example –In the code given below there are three statements which are terminated by semicolon(;).
Use of a comment is shown in below example-
Some rules are defined for the naming of identifiers –
In the following example-
Compiler totally ignores the white spaces in your program. We are free to place the things in our code anywhere we want. White space improves the readability of our code, it makes our code understandable and clear.
Statement Terminator in C –
A C program is a group of statements and each statement in C is terminated with a semicolon (;) and is called statement terminator. In a C program a statement can have any number of lines and a semicolon indicates that a statement has been ended.For Example –In the code given below there are three statements which are terminated by semicolon(;).
#include <stdio.h> #include <conio.h> void main(){ printf("this is statement one"); printf("this is statement two"); printf("this is statement three"); }
Explaining a code in C –(Comments in C)
Comments are the statements which are ignored by the compiler and are used for explaining the code. Comments in C starts with /* and ends with */. We can write anything between /* and */ to explain our code.Use of a comment is shown in below example-
#include <stdio.h> #include <conio.h> void main(){ printf("hello world"); /*above statement will print hello world string*/ }
Identifiers in C-
C identifiers are the names which are used to identify various elements in C program like variables , functions and some other user defined items.Some rules are defined for the naming of identifiers –
- An identifier should start with a letter A to Z or a to z or a or an underscore(_).
- Identifiers are case sensitive ie WORD and word are two different identifiers.
- We cannot use any special character like @, $, and % as identifiers.
- C reserved words cannot be used as identifiers.
Here is a list of C reserved words
auto | else | switch | long |
enum | break | typedef | register |
extern | return | union | case |
float | char | short | unsigned |
signed | void | for | const |
goto | sizeof | volatile | continue |
if | static | while | default |
struct | do | int | _Packed |
double |
Importance of whitespace in C programming-
A C program is a series of statements. Two parts of a statement are separated by inserting a whitespace between them. A whitespace tells the compiler , where one element in a statement ends and the next element begins.In the following example-
#include <stdio.h> #include <conio.h> void main(){ int size; }Two elements int and size are separated by a whitespace for the understanding of compiler.
Compiler totally ignores the white spaces in your program. We are free to place the things in our code anywhere we want. White space improves the readability of our code, it makes our code understandable and clear.
Subscribe to:
Post Comments
(
Atom
)
No comments :
Post a Comment