0% found this document useful (0 votes)
1 views24 pages

C Programming Study Material-Computer DRT

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

C Programming Study Material-Computer DRT

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

VELAMMAL BODHI CAMPUS

ANUPPANADI

CLASS -8

C
PROGRAMMING
What is Computer ? What is a program?
Computer – a tool to Program -is a sequence
solve problems. of instructions.
INTRODUCTION TO PROGRAMMING
LANGUAGES

 A computer is a device that process the data with the help of a


computer program.
 A program is a sequence (order) of instructions along with data.
Consider the following example.
1. Get two numbers from your friend.
2. Add the two numbers and write the result in the first paper.
3. Subtract the two numbers and write the result in the second paper.
4. Find the square of the first number and write the result in the third
paper.
5. Read out the three answers one by one.
Here:
• Input -> Step 1 Processing -> Step 2 to 4
• Output -> Step 5
TYPES OF PROGRAMMING LANGUAGE

• low-level programming language - machine language(0 0r 1 ).


• high-level programming language -closer to human language
TYPES OF TRANSLATOR

A translator is software which is used to translate high


level language as well as low level language in to machine
level language.

TRANSLATO
R

Assembler Interpreter Compiler


MACHINE
SOURCE CODE ASSEMBLER LANGAGE CODE

SOURCE
PROGRAM INTERPRETE OUTPU
R T
INPUT

SOURCE TARGET
COMPILER
PROGRAM PROGRAM

ERROR
MESSAGE
A FEW POPULAR PROGRAMMING LANGUAGES

C
C++
Python
Java
SCALA
C#
R
Ruby
Go
Swift
DIFFERENCE BETWEEN SOURCE CODE AND OBJECT
CODE.

Source Code Object Code


• Source code is in the form of • Object Code is in the form of
Text form. Binary Numbers.
• Created by the programmer • Created by the Compiler
• Source code is Human • Object Code is in Machine
Readable Code. Readable formats.
• Source code is Generated by • Object Code is Generated by
Human or Programmer. Compiler.
• Source code is received by • Object Code is Generated by
Compiler as a Input. Compiler as a Output.
RULES FOR WRITING A C PROGRAM

• Rule 1: All statement should be written in lowercase letters.


• Rule 2: Uppercase letter can be used only for symbolic constants.
• Rule 3: Blank spaces may be inserted between the words. This
improves the readability of statements.
• Rule 4: Blank spaces should not be allowed while declaring variables,
constants, keyword, function.
• Rule 5: Programmer can write the statement anywhere between the "2
braces". { }
• Rule 6: Programmer can write one or more statement in one line,
separating that by semicolon (;).
• Rule 7: Opening and closing "braces" must be balanced. ( )
• Rule 8: Program must contain a main function.
INTRODUCTION TO 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.
• It was mainly developed as a
system programming
language to write an
operating system.
WHERE TO TYPE THE PROGRAMS?
Turbo C++ compiler can be downloaded from the following link.
https://turbo-c.soft32.com type the program and save the program by
giving a file name with extension .c in case of a C program and .cpp
extension in case of a C++ program. To compile and execute the
program to see the
output, press ‘Ctrl + F9’ key combination.
 Dev C++ compiler can be downloaded from the following link.
https://dev-c.soft32.com
then type the program and save the program as done in Turbo C++
compilerTo compile and execute the program, press F11 key.
STRUCTURE OF A C PROGRAM

C programming language is a case


sensitive language.
The structure of a C program is as
follows:
1. Header Files
2. Main function
3. Variable declaration
HEADER FILES

A header file is a file with extension .h which


contains many C function declarations.
They are included in a program using a state-
ment called preprocessor directive state-
ment.
The compiler searches the header file for
what is to be done when printf( ) function exists
in a program
C HEADER FILES
• stdio.h – Defines core input and output functions
• string.h – Defines string handling functions
• math.h – Defines common mathematical functions
Syntax to include a header file in C:
#include <headerfile.h>
Eg :

#include<stdio.h>
#include<string.h>
#include<math.h >
MAIN METHOD DECLARATION

• The next part of a C program is to declare the main() function.


• main() function is the entry point of any C program.
• It is the point at which execution of program is started. When a
C program is executed, the execution control goes directly to the
main() function.
• Every C program have a main() function.
Syntax to Declare main method:
int main( )
{
Body of the main function
return 0;
}
VARIABLE DECLARATION:

• The next part of any C program is the variable declaration.


• It refers to the variables that are to be used in the
function. (place where the values are stored )
• The variables should be declared at the beginning of
the main( ) function.
Example:

int main( )
{
int a; // variable a is declared
}
BODY OF THE FUNCTION
Body of a function in C program refers to the in-
structions or operations that are performed.
int main()
{
int a=8;
a=a+10;
printf(“%d”,a); Body of the function
return 0;
}

You might also like