- BEGINNING OF A C PROGRAM
- COMPILING OF A C PROGRAM
- KEYWORDS AND IDENTIFIERS
- STATIC AND GLOBAL VARIABLE
Let’s understand components and keywords in brief
Header file
The first line, or keyword, of a
C Language program is #include<stdio.h>. The shared header data
for the program, like as declarations, functions, and macro definitions, are
included in (.h) files.
They are processed by the
pre-processor, which the compiler calls.
Here are a few more typical
applications for header files: -
A Stddef.h is useful for macros.
There is Stdint.h for integer
types with precise widths.
See Stdio.h for basic
input/output functions.
Functions for converting numbers,
allocating memory, and generating pseudo-random numbers are included in
Stdlib.h.
See String.h for functions that
deal with strings.
See Math.h for commonly used mathematical functions.
Body of the method (enclosed in{})
The main manipulation will hold in the body
part. It can be like anything as manipulations, searching, sorting, printing, etc.
The functions have to be in the braces.
Print statement (line 4)
Printf(“ hello world”);
This statement was given to the compiler and
in C it is always terminated by ;(semicolon).
We use a function called printf() to display
the typed text on the monitor as output.
Return statement
It is called the last section of the C program. This is a reference to the values that a function returns. These values and the function are dependent on the return type of the function such as main().
Maybe it is used by our OS to know the
termination status of the program as 0 indicates the successful termination.
Compiling
a C program
We already know that C language is a mid-level programming language that needs a compiler to execute code this compiler converts the code into a machine-level language that is then used by the machine to run.
In a simple language, we can easily understand it as
In compilation, it converts the (.i) file into an assembled file
(.s) containing assembly-level instructions.
An assembler is used to convert the (.s) assemble level code to
machine-readable code like binary/hexadecimal code known as object code.
In Linking it integrates library files into the program. The linking process creates an executable file with an extension as (.exe) in DOS and (.OUT) in the Unix Operating system.
Q) what is an executable file?
An executable file is a set of files full of instructions encoded with
sequence instructions that the system can execute directly as the user clicks
on it and executes their program. It has many types of extensions like .exe,
.bat, .com, .cmd, .inf, .ipa, etc.
EXE refers to
an executable file, meaning that all EXE files are capable of being executed,
whereas not all executable files are EXE.
Q) Using a terminal to run a very first program?
Q) what is a variable, and constant, and how to declare variables and
naming conventions?
The combination of proper alphabets, numerals, and special symbols with constants, variables, and keywords. Let us understand what is a constant and a variable.
Let’s assume the variable is an empty container that contains any type
of value that is being employed
inside the program to resolve mathematical calculations. A variable name can have at
most 31 characters, which means if we try to write a variable name with 32 then
it will not be supported by C language.
The constant is a static entity that may not change its actual position.
We can also state this as a variable is a container that contains the static
values to solve the mathematical calculations.
Variety of C constants
a)
Primary constants
·
Integer constants
·
Real constants
·
Character constant
b)
Secondary constants
·
Array
·
Pointer
·
Structure
·
Union
·
Enum, etc.
Keywords and identifiers
C Programming keywords are specified, reserved words with specific
meanings that are assigned by the compiler. Keywords cannot be used as
identifiers because they are an essential part of the syntax. As an
illustration:
Int city;
In this case, the keyword int designates that the variable money is an
integer of type int.
Since the language C is case-sensitive, all keywords have to be written
in lowercase. This is a list of all ANSI C-acceptable keywords.
IDENTIFIERS
The basic units of a program in the C programming language are called
identifiers. Functions, variables, structs, and other entities are given unique
names called identifiers. They serve as the entity's special identification
within the program. In
the example below, the string type value is identified as "section."
Rules for Naming Identifiers
While naming variables, a programmer must adhere to specific guidelines.
The rules listed below must be adhered to for the identification to be valid.
Both numerals (0–9) and letters (a–z or A–Z) can be used as
identification.
All that is permitted in identification is the underscore '_'.
You cannot use spaces while naming as an identifier.
Only letters or an underscore may start an identifier.
Since identifiers are words that are reserved for a particular purpose,
we cannot name them similarly to keywords. Printf, scanf, int, char, struct,
etc. are a few examples. If
we try to use a keyword's name as an identifier, the compiler will throw an
error.
Within its namespace, the identification needs to be unique.
Because C is a case-sensitive language, "name" and
"NAME"
Static variable and global
variable
Variables defined outside of the function are referred to as global
variables. Global variables have an end-of-file or program scope, which starts
at the moment of formation. a result of their external linkage, references to the same memory address
in different source files.
Static global variables do not clash with other variables of the same
name in other source files because they are specific to the source file in
which they are defined.
Both static and global variables have static initialization, which
implies that in cases where you don't set a value for them, NULL (for pointers)
or 0 (for common variables) will be provided.
No comments:
Post a Comment