0% found this document useful (0 votes)
5 views

Basic Structure & Syntax CodeWithHarry

The document outlines the basic structure and syntax of programming in C, detailing components such as pre-processor commands, functions, variables, and comments. It explains the significance of header files, keywords, identifiers, constants, and string literals in C programming. The document also provides examples to illustrate how a basic C program is structured and the rules for naming identifiers.

Uploaded by

Adesh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Basic Structure & Syntax CodeWithHarry

The document outlines the basic structure and syntax of programming in C, detailing components such as pre-processor commands, functions, variables, and comments. It explains the significance of header files, keywords, identifiers, constants, and string literals in C programming. The document also provides examples to illustrate how a basic C program is structured and the rules for naming identifiers.

Uploaded by

Adesh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

CodeWithHarry Menu Login

Previous Next

Basic Structure & Syntax


Programming in C involves following a basic structure throughout. Here’s what it can be broken down to.
◦ Pre-processor commands
◦ Functions
◦ Variables
◦ Statements
◦ Expressions
◦ Comments

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

CodeWithHarry Copyright © 2022 CodeWithHarry.com

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy