Introduction to Programming in C - Prof. Ansar, Lecture notes of Programming Languages

An overview of the c programming language, including its history, features, and the structure of a c program. It covers the differences between low-level and high-level programming languages, the role of compilers and interpreters, and the steps involved in compiling and executing c programs. The document also introduces the concept of integrated development environments (ides) and the key components of a c program, such as comment lines, preprocessor directives, and the main() function. This comprehensive introduction to c programming would be valuable for students or learners who are new to the language and want to understand its fundamental concepts and development process.

Typology: Lecture notes

2021/2022

Uploaded on 06/13/2024

midhuna-satheesh
midhuna-satheesh 🇮🇳

1 / 5

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
PROGRAMMING IN C
C is a programming language developed at AT & T’s Bell Laboratories of USA . In 1972
it was designed and written by a man named Dennis Ritchie. In the late Seventies C
began to replace the more familiar languages of that time like PLALGOL, etc.
It was initially designed for programming UNIX Operating system. Now the software
tool as well as the C compiler is written in C.
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.
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.
So for as programming language concern these are of two types.
1) Low level language
2) High level language
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.
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.
Three types of translator are there:
Compiler
pf3
pf4
pf5

Partial preview of the text

Download Introduction to Programming in C - Prof. Ansar and more Lecture notes Programming Languages in PDF only on Docsity!

PROGRAMMING IN C

  • C is a programming language developed at AT & T’s Bell Laboratories of USA. In 1972 it was designed and written by a man named Dennis Ritchie. In the late Seventies C began to replace the more familiar languages of that time like PLALGOL, etc.
  • It was initially designed for programming UNIX Operating system. Now the software tool as well as the C compiler is written in C.
  • 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.
  • 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.
  • So for as programming language concern these are of two types.
    1. Low level language
    2. High level language 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. 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.

Three types of translator are there:

  • Compiler
  • Interpreter
  • 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.

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. Structure of C Language program 1 ) Comment line

  1. Preprocessor directive 3 ) Global variable declaration
  2. main function( ) {

The main( ) function return value when it declared by data type as int main( ) { return 0 } The main function does not return any value when void (means null/empty) as void main(void ) or void main() { Printf (“C language”); } Output: C language /First c program with return statement/ #include <stdio.h> int main (void) { printf (“welcome to c Programming language.\n”); return 0; } Output: welcome to c programming language.

Steps for Compiling and executing the Programs.

Step 1: The program that is to be compiled is first typed into a file on the computer system. There are various conventions that are used for naming files, typically be any name provided the

last two characters are “.c” or file with extension .c. So, the file name prog1.c might be a valid filename for a C program. A text editor is usually used to enter the C program into a file. Step 2: After the source program has been entered into a file, then proceed to have it compiled. The compilation process is initiated by typing a special command on the system. When this command is entered, the name of the file that contains the source program must also be specified. Step 3: When all the syntactic and semantic errors have been removed from the program, the compiler then proceeds to take each statement of the program and translate it into a “lower” form that is equivalent to assembly language program needed to perform the identical task. Step 4: After the program has been translated the next step in the compilation process is to translate the assembly language statements into actual machine instructions. The assembler takes each assembly language statement and converts it into a binary format known as object code, which is then written into another file on the system. Step 5: After the program has been translated into object code, it is ready to be linked. This process is once again performed automatically whenever the cc or gcc command is issued under Unix. The purpose of the linking phase is to get the program into a final form for execution on the computer. Step 6: To subsequently execute the program, the command a.out has the effect of loading the program called a.out into the computer’s memory and initiating its execution.