0% found this document useful (0 votes)
13 views

1.Introduction to C

The document provides an overview of programming languages, categorizing them into low-level (machine and assembly languages) and high-level languages (like C, C++, Python). It discusses the evolution of the C programming language and includes a simple C program example, explaining its components such as comments, the main function, and statements. Additionally, it outlines the role of translators like assemblers, compilers, and interpreters in converting code into machine language.

Uploaded by

Dilu Sandalika
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views

1.Introduction to C

The document provides an overview of programming languages, categorizing them into low-level (machine and assembly languages) and high-level languages (like C, C++, Python). It discusses the evolution of the C programming language and includes a simple C program example, explaining its components such as comments, the main function, and statements. Additionally, it outlines the role of translators like assemblers, compilers, and interpreters in converting code into machine language.

Uploaded by

Dilu Sandalika
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

Introduction to

Objective:

• Describe the evolution of programming languages


• Write a simple C program

1
Computer Program
▪ Computer Program

Set of instructions given to the computer.


▪ Programmers write programs in various programming
languages.
▪ Programming languages can be mainly divided into :
1. Low-level programming languages
- Machine Language
- Assembly Language
2. High-level programming languages
2
Computer Program
1. Low-level programming Languages
▪ Machine Languages
• Consist of 1 s and 0 s
• Machine dependent
• Computer can directly understand its own machine
language
• Tedious and error prone for programmers

3
Computer Program
▪ Assembly Languages
• English-like abbreviations called mnemonics formed the basis
• Clearer to humans but incomprehensible to computers
• Need to translate to machine language using translator
programs called assemblers
Example: load salary
add bonus
store total

4
Computer Program
2. High Level Programming Languages
• Instructions look almost like English and mathematical notations
• Substantial tasks can be accomplished from a single statement
• Easy for humans to understand
• Translator programs convert high-level programming languages
into machine language
Example: total = salary + bonus;
• C, C++, Python, Visual Basic and Java are some of the high-level
programming languages
5
Program code Translation
▪ Translator

- Assemblers (convert assembly language programs to machine


language)
- Compilers (convert high-level language programs to machine language)

- Interpreters (execute high-level language programs line by line)

Object Code –
Source Code Translator Machine Language Code

6
History of C
▪ C language was evolved from two previous languages, BCPL and B by
Dennis Ritchie at Bell Laboratories in 1972.
▪ C initially became widely known as the developing language of the
UNIX operating system.
▪ C99 and C11 are revised standards for C programming language that
refines and expands the capabilities of C

7
Simple C Program

8
Simple C Program
/* First program in C This program displays a // function main begins program
message */ execution

▪ These are comments.


▪ Comments are used to document programs and it improves the program readability.
▪ C compiler ignores comments.
▪ Line comments begin with // and continue for the rest of the line. /* … */ multi-line comments can
also be used.
▪ Everything from /* to */ is a comment.

#include <stdio.h>

▪ This is a directive to C preprocessor.


▪ Lines begin with # are processed by the preprocessor before compiling the program.
▪ Here, preprocessor includes the content of stdio.h in the program. stdio.h is a header file which
contains information about standard input/output library function calls such as printf.

9
Simple C Program Description
int main(void)
▪ Every C program has this main function, and it begins executing at main. “int” to left of main
indicates that the function returns an integer. “void” in parentheses indicates that main does not
receive any information

{
▪ Left brace , { , begins the body of every function.
▪ Functions ends with a corresponding right brace.
▪ The portion of the program between the braces is called a block.

printf(“Welcome to C”);
▪ Entire line is called a statement.
▪ It instructs the computer to perform an action.
▪ A statement must end with a semicolon.
▪ This statement prints a string of characters marked by the quotation marks on the screen
10
Simple C Program Description
Return 0;

• Included at the end of every main function.


• It is used to exit the main function and the value 0
indicates a successful termination.
Blank Lines and White Space
• Blank lines, space characters and tab characters are
known as white space.
• White-space characters are normally ignored by the
compiler.
11
C Program Development
Environment

12
More examples

• The backslash (\) is called escape character.


• The escape sequence \n means newline.
13
14

You might also like