Programming C
Programming C
o Clang
educational institutions)
3.Operating System: C programs are usually
compiled to run on a variety of operating
systems, such as Windows, Linux, or macOS.
C Program Structure
A typical C program is structured in a specific way
to ensure readability and functionality:
1.Preprocessor Directives: These are lines
that begin with #, like #include <stdio.h>,
which tell the compiler to include external files
or libraries.
2.Global Declarations: These can include
variables or functions that are used throughout
the program.
3.Main Function: Every C program must have a
main() function. This is the entry point of the
program where execution begins.
4.Statements and Expressions: Inside
functions, you write statements that perform
actions, such as calculations, input, output, and
more.
5.Return Statement: The main() function
typically ends with return 0;, indicating
successful program completion.
Tokens in C
Tokens are the smallest units of a C program.
These include:
1.Keywords: Reserved words with special
meaning, such as int, if, while, return, for, char.
2.Identifiers: Names given to variables,
functions, and other user-defined items (e.g.,
main, num, sum).
3.Constants: Fixed values like numbers or
characters (e.g., 100, 3.14, 'a').
4.Operators: Symbols used for operations, such
as +, -, *, /, =, ==.
5.Punctuation: Characters used for program
structure, such as semicolons ;, commas ,,
parentheses (), curly braces {}.
Flowcharts and Pseudocodes
Before writing the actual C code, it is common to
design a program using flowcharts and
pseudocodes:
Flowchart: A visual representation of the
steps in a program. Each operation is
represented by shapes like rectangles
(processes), diamonds (decisions), and arrows
(flow of execution).
o Example: A flowchart for checking if a
3.14, -5.6).
o double: Stores double-precision floating-
'#').
o void: Represents the absence of any type