0% found this document useful (0 votes)
32 views14 pages

CSE287JUL2021 - LectureSlide - 02 (Introduction To C)

This document provides an introduction to the C programming language in a lecture for an engineering course. It discusses that C was invented in the 1970s and is a middle-level language with a structured approach. It then examines the basic structure of a C program, including the preprocessor, header files, the main function, library functions, and statements. Finally, it outlines the lifecycle of a C program from source code to executable file.

Uploaded by

Khaled Mahmud
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)
32 views14 pages

CSE287JUL2021 - LectureSlide - 02 (Introduction To C)

This document provides an introduction to the C programming language in a lecture for an engineering course. It discusses that C was invented in the 1970s and is a middle-level language with a structured approach. It then examines the basic structure of a C program, including the preprocessor, header files, the main function, library functions, and statements. Finally, it outlines the lifecycle of a C program from source code to executable file.

Uploaded by

Khaled Mahmud
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/ 14

CSE287

Computer Programming

Lecture 2:
Introduction to C

Khaled Mahmud Shahriar


Assistant Professor
November 15, 2021 Department of CSE, BUET Offered to: Department of MME, L-2, T-1
About C
• Invented and first implemented by Dennis Ritchie at
Bell Labs in the early 1970s
• Middle level language
• Structured and disciplined approach to computer
program
• ANSI (American National Standards Institute)
approved a standard in 1989
• For details, see:
https://en.wikipedia.org/wiki/C_(programming_lang
uage)

2
A first look at C
Preprocessor
Header file
Directive

Return type Main function


Start of function
Library function Statement

End of function

Keyword Function Function


return value parameter/argument

A simple C program
3
A first look at C

#include
• # symbol indicates a preprocessor
• It means it has to be done before compilation
• #include to include the contents of the header file

4
A first look at C

<stdio.h>
• Name of the header file • Enclosed in < > (header in default
• Header files: constants, functions, other place)
declarations • May be enclosed in “ ” (header is in the
• You must know which header you need same folder as the source)
• Use help and documentation to find out • stdio.h : standard input/output header
file
5
• Needed for the function: printf()
A first look at C

main
• Every C program must have a ‘main’ function
• Program starts from the 1st line in ‘main’
• Parameter type void
• Return type int
• int main()
6
A first look at C

{ } curly braces
• The curly braces are like containers • Left curly brace {
• The code between two braces are called a block • Begin the body of function
• Missing either brace will generate compile error • Right Curly brace }
• “Compound Statement missing” • End of the function

7
A first look at C

printf
• A function given in stdio.h
• Prints the text given as the parameter

8
A first look at C

; (semicolon)
• Every C statement must end with a ;
• Otherwise compiler will generate an error
• Statement Missing

9
A first look at C

return 0
• Indicate how the program exited
• return 0 means that execution was successful and there was no error.
• abnormal termination is usually signaled by a non-zero return
• but there is no standard for how non-zero codes are interpreted.
• When a program is called by another program
10
Basic Structure of a C Program
• Function • Header file
• Building Block • .h extension
• Named subroutine • Add header file using #include
• Can be called by other parts of the (preprocessor directive)
program • Statement
• A program may contain more than
• Action performed by the program
one functions
• One of which must be main()
• Perform operations
• Where execution begins • End with a semicolon (;)
• Two or more statements can be
• Standard library placed on a single line
• Provides library functions
• Example: I/O operation, string,
math … etc

11
Lifecycle of a C Program

User defined Standard


Source
Header File Header File
File
Compile Compile
Compile
Link
Library File
Object File

Executable
File
Acknowledgement
All the slides of this course have been prepared by taking help from numerous resources.
The notable contributors are listed below.
1. Content and organization of many pages have been taken from the lecture slides and
codes of the course CSE110 offered to the Department of EEE that were -
i. primarily created by Johra Muhammad Moosa, Assistant Professor (on leave),
CSE, BUET and
ii. later modified by Madhusudan Basak, Assistant Professor, CSE, BUET
2. Most of the wonderful coding examples have been taken from the course CSE281
offered to the Department of BME instructed by Rifat Shahriyar, Professor, CSE,
BUET (course link).
3. search and all the sites that it made available in response to the course
related queries. Some of the sites are: https://geeksforgeeks.org/,
https://www.tutorialspoint.com, https://www.w3schools.com and the list goes on …
Thank You

14

You might also like