Program :- DAY-01
There is a close analogy between learning English language and learning C language.
The classical method of learning English is to first learn the alphabets used in the language, then learn to combine these alphabets to form words, which in turn are combined to form sentences and sentences are combined to form paragraphs.
Learning C is similar and easier. Instead of straight-away learning how to write programs, we must first know what alphabets, numbers and special symbols are used in C, then how using them constants, variables and keywords are constructed, and finally how are these combined to form an instruction.
A group of instructions would be combined later on to form a program.
So a computer program is just a collection of the instructions necessary to solve a specific problem.
The basic operations of a computer system form what is known as the computer's instruction set.
And the approach or method that is used to solve the problem is known as an algorithm.
In simple words.....
1. A program is like a set of instructions.
2. It tells a computer what to do.
3. It's written using a programming language.
4. It can perform calculations, tasks, or solve problems.
5. Programs can be small or very large.
6. They can be games, apps, or tools.
7. A program needs a computer to run on.
8. It can be stored on a disk or downloaded.
9. The computer's processor executes the program's instructions.
10. Programs make computers useful for various tasks.
So for as programming language concern these are of two types.
1) Low level language
2) High level language
1.Low level language:
Low level languages are machine level and assembly level language.
In machine level language computer only understand digital numbers i.e. in the form of 0 and 1.
So, instruction given to the computer is in the form binary digit, which is difficult to implement instruction in binary code.
This type of program is not portable, difficult to maintain and also error prone. The assembly language is on other hand modified version of machine level language.
Where instructions are given in English like word as ADD, SUM, MOV etc.
It is easy to write and understand but not understand by the machine. So the translator used here is assembler to translate into machine level.
Although language is bit easier, programmer has to know low level details related to low level language.
In the assembly level language the data are stored in the computer register, which varies for different computer. Hence it is not portable.
In simple words
1. Low-level language is close to the computer's hardware.
2. It directly uses basic instructions that hardware understands.
3. It's not easy for humans to read or write.
4. In C, low-level operations involve memory addresses and raw data.
5. It lacks the human-friendly features of high-level languages.
6. Low-level code is specific to a particular computer architecture.
7. It gives precise control over hardware resources.
8. It's more efficient for certain specialized tasks.
9. Low-level operations are represented using binary code.
10. Unlike high-level languages, low-level code needs to be tailored to the exact machine it's running on.
2.High level language:
These languages are machine independent, means it is portable. The language in this category is Pascal, Cobol, Fortran etc.
High level languages are understood by the machine. So it need to translate by the translator into machine level.
A translator is software which is used to translate high level language as well as low level language in to machine level language.
In simple words .......
1. High-level language is like regular English for computers.
2. It's designed for humans to easily read and write.
3. It uses words and syntax closer to human language.
4. Instructions are abstracted from hardware specifics.
5. It's not tied to a specific computer's architecture.
6. Programs written in high-level languages are portable.
7. They need an interpreter or compiler to run.
8. Common high-level languages include Python, Java, and C++.
9. High-level code is easier to debug and maintain.
10. It's preferred for most software development due to its readability and portability.
Three types of translator are there:
1.Compiler
2.Interpreter
3.Assembler
Compiler and interpreter are used to convert the high level language into machine level language.
The program written in high level language is known as source program and the corresponding machine level language program is called as object program.
Both compiler and interpreter perform the same task but there working is different.
Compiler read the program at-a-time and searches the error and lists them.
If the program is error free then it is converted into object program.
When program size is large then compiler is preferred. Whereas interpreter read only one line of the source code and convert it to object code.
If it check error, statement by statement and hence of take more time.
1) Compiler :
1. A compiler is a special computer program.
2. It helps translate human-written code.
3. This code is in a high-level language.
4. High-level code is easy for humans to read.
5. Compiler turns it into machine code.
6. Machine code is what computers understand.
7. It's a set of 0s and 1s.
8. Compiler does this all at once.
9. It reads the entire program.
10. Then, it changes it into machine code.
11. This process is called compilation.
12. Once compiled, code runs faster.
13. Compiler checks for errors in code.
14. It helps find mistakes.
15. It creates an executable file.
16. This file is ready to run.
17. Different languages have different compilers.
18. Examples include C, C++, Java compilers.
19. It's a key part of software development.
20. Helps programmers turn ideas into working programs.
2) Interpreter :
1. An interpreter is a computer program.
2. It reads and executes code.
3. Code is written in a high-level language.
4. High-level code is human-friendly.
5. Interpreter works line by line.
6. It doesn't need prior compilation.
7. Translates code on-the-fly.
8. Makes debugging easier.
9. Slower than compiled languages.
10. Offers real-time feedback.
11. Common in scripting languages.
12. Python and JavaScript use interpreters.
13. Ideal for rapid prototyping.
14. Doesn't produce an executable file.
15. Executes code directly in memory.
16. Interprets code dynamically.
17. Used for automation tasks.
18. Common in web development.
19. Allows interactive coding.
20. Useful for experimenting and learning.
3)Assembler
1. An assembler is a program.
2. It converts assembly language into machine code.
3. Assembly language is human-readable.
4. Machine code is computer-readable.
5. Assembly uses mnemonics.
6. Mnemonics represent instructions.
7. Instructions are basic operations.
8. Assembler translates mnemonics to binary.
9. Binary is the language computers understand.
10. It creates an object file.
11. Object file contains machine code.
12. Object file needs a linker to run.
13. Linker combines object files.
14. It resolves external references.
15. Produces an executable file.
16. Executable file runs a program.
17. Assembler is specific to a CPU architecture.
18. Different CPUs have different assemblers.
19. It's closer to machine language than high-level languages.
20. Used in systems programming and embedded systems.
Integrated Development Environments (IDE) :
The process of editing, compiling, running, and debugging programs is often managed by a single integrated application known as an Integrated Development Environment, or IDE for short. An IDE is a windows-based program that allows us to easily manage large software programs, edit files in windows, and compile, link, run, and debug programs.
On Mac OS X, CodeWarrior and Xcode are two IDEs that are used by many programmers. Under Windows, Microsoft Visual Studio is a good example of a popular IDE. Kylix is a popular IDE for developing applications under Linux. Most IDES also support program development in several different programming languages in addition to C, such as C# and C++.
1. An IDE is a software.
2. It helps write C code.
3. Provides a code editor.
4. Offers tools for development.
5. Examples: Code::Blocks, Dev-C++, Visual Studio.
Structure of C Language program
1) Comment line
2) Preprocessor directive
3) Global variable declaration
4) main function()
Structure of C program and Simple Example of C language with program :
A basic structure of a C program typically consists of the following parts:
1. Preprocessor Directives : These are instructions for the preprocessor. They start with `#`. Common examples include `#include` which includes header files and `#define` for defining constants.
In Simple words....
1. Preprocessor directives start with `#`.
2. They are special commands in C.
3. They guide the preprocessor, a part of the compiler.
4. Common ones include `#include` for adding libraries.
5. They help customize code before actual compilation.
2. Main Function(int main( ) { }):
This is where program execution begins. It must be present in every C program. It returns an integer value to indicate the program's exit status.
1. The main function is like a boss.
2. It's where a C program begins.
3. It must always be present.
4. It's written as `int main()`.
5. It can return a number to show if the program ran well.
3. Declaration Section : This is where variables, constants, and functions are declared. It's good practice to declare variables at the beginning of a function.
1. Declaration section is like a list.
2. It's where you declare things.
3. You state variables and their types.
4. It comes before actual work starts.
5. Helps organize what you'll use later.
4). Executable Statements : These are the actual instructions or actions the program performs. They are written in C language syntax.
1. Executable statements are like actions.
2. They are the real work of the program.
3. They perform tasks like math or printing.
4. Written in C language instructions.
5. These make the program do things.
5). Comments : These are not essential but are crucial for code readability and documentation. They begin with `//` for single-line comments or are enclosed within `/* ... */` for multi-line comments.
1. Comments are like notes.
2. They help explain code.
3. They don't affect program execution.
4. Written for humans to understand.
5. Start with `//` for one line or `/* ... */` for many lines.
6).Functions ( ): Programs can be divided into functions for modularity and reusability. Apart from `main()`, custom functions can be created.
1. Functions are like mini-programs.
2. They do specific tasks.
3. You can create your own functions.
4. They make code organized and reusable.
5. Main function is one special function.
Here's an example of a simple C program:
#include <stdio.h>
int main() {
// Declaration section
int num1, num2, sum;
// Executable statements
printf("Enter two numbers: ");
scanf("%d %d", &num1, &num2);
sum = num1 + num2;
printf("Sum is: %d", sum);
return 0; // Indicates successful execution
}
```
This program prompts the user for two numbers, adds them, and then displays the sum.
Remember, this is a basic structure. Real-world programs can be much more complex, incorporating additional features like loops, conditional statements, and various functions.

Comments
Post a Comment