Basic Structure & Syntax CodeWithHarry
Basic Structure & Syntax CodeWithHarry
Previous Next
PPrree--pprroocceessssoorr ccoom
mmmaannddss
Pre-processor commands are commands which tell our program that before its execution, it must include the �le name mentioned in it because we are using some of the commands or codes from this �le.
They add functionalities to a program.
One example could be,
#include <math.h>
We include math.h to be able to use some special functions like power and absolute. #include<�lename.h> is how we include them into our programs.
Detailed explanations of everything else in the structure will follow in the later part of the tutorial.
H
Heeaaddeerr �
�lleess::
� Collection of predefined/built in functions developed
� It is always declares on heading side of program hence it is called header file
� It is identified with the extension(.h)
� It gets installed while installing IDE(integrated development environment)
� It stores functions as per their categories hence they are called library
SSyynnttaaxx
An example below shows how a basic C program is written.
Declaration of header file //name of the header files of which functions are been used
main(
main () /*it is called main function which stores the execution of program*/
{ //start of the program
//program statements
} //end of the program
▪ Here, the �rst line is a pre-processor command including a header �le stdio.h.
▪ C ignores empty lines and spaces.
▪ There is a main() function then, which should always be there.
A C program is m
maaddee uupp ooff ddiiffffeerreenntt ttookkeennss ccoom
mbbiinneedd. These tokens include:
• Keywords
• Identi�ers
• Constants
• String Literal
• Symbols
KKeeyyw
woorrddss
Keywords are reserved words that can not be used elsewhere in the program for naming a variable or a function. They have a speci�c function or task and they are solely used for that. Their functionalities are
pre-de�ned.
One such example of a keyword could be return which is used to build return statements for functions. Other examples are auto, if, default, etc.
Whenever we write any keyword in IDE their colour slightly changes and it looks different from other variables or functions for example in turbo c all keywords are turns into white colour .
IIddeennttii�
�eerrss
Identi�ers are names given to variables or functions to differentiate them from one another. Their de�nitions are solely based on our choice but there are a few rules that we have to follow while naming
identi�ers. One such rule says that the name can not contain special symbols such as @, -, *, <, etc.
C is a case-sensitive language so an identi�er containing a capital letter and another one containing a small letter in the same place will be different. For example, the three words: Code, code, and cOde can
be used as three different identi�ers.
Rules for naming identi�er-
1. One should not name any identi�er starting with numeric value or symbol. It should start only with underscore or alphabet
2. They should not contain space
3. Giving logical names is recommended as per our program
CCoonnssttaannttss
Constants are very similar to a variable and they can also be of any data type. The only difference between a constant and a variable is that a constant’s value never changes. We will see constants in more
detail in the upcoming tutorial.
SSttrriinngg LLiitteerraall
String literals or string constants are a sequence of characters enclosed in double quotation marks. For example, “This is a string literal!” is a string literal. C method printf() utilizes the same to format the
output.
Previous Next