unit-5-programing-concept-and-logic
unit-5-programing-concept-and-logic
ADD A, B Add B to A
Fig: Assembler
It is faster than compiler and Interpreter
It produces binary machine code.
Difficult to trace errors.
It is most efficient than compiler and
interpreter.
Examples: x86, ARM etc.
Assignment:
1970 B Ken Thompson (AT & T Bell Lab) Could deal with only
specific problems
Documentation
// Write a program to to add any two number and display it
return 0;
1. Documentation
Documentation refers to the comments and descriptions
included in the code to explain its purpose, structure, and
functionality.
It makes the code easier to read, maintain, and debug.
Documentation doesn't affect program execution; it is for the
benefit of developers.
It may includes:
/*
* File Name: <file_name>.c
* Author: <your_name>
* Date: <creation_date>
* Version: <version_number>
* Description: <short_description_of_file_purpose>
*/
2. C Preprocessor and Header Files
The C preprocessor is a program that processes the
source program before it is passed to the compiler for
compilation.
The preprocessor offers several features, which known as
preprocessor directives.
The preprocessor directives begin with a # symbol.
Such directives can be placed anywhere in the program but
are mostly placed at the beginning of a program.
Preprocessor directives are not program statements and so
that they are not terminated by a semicolon.
Header Files:
C header files are used to provide why of telling the
compiler what interface specific function requires in
order to be used.
The header files give the information to the compiler
that what actually the source code does.
In c, the usually convention is to give header file
names that end with .h.
The standard libraries of header files include
the followings.
4. main() Function
The entry point of the program where execution begins.
Example:
int main() {
// Your code
return 0; // Indicates successful execution
}
5. Variable Declarations
Declare variables inside main() or other functions.
Example:
int a, b, sum;
6. Program Logic
Write the logic using operators, conditionals, loops,
and function calls.
Example:
9. Return Statement
•End the main() function with return 0;.