0% found this document useful (0 votes)
13 views27 pages

EEE103 Lec02 and Lec03

The document provides an introduction to C programming, covering essential concepts such as abstraction, the structure of a C program, and key components like header files and functions. It explains the importance of variables, data types, and operators in C, along with guidelines for variable naming and memory allocation. Additionally, it highlights the role of compilers, IDEs, and documentation in the programming process.

Uploaded by

mohsin.islam
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 views27 pages

EEE103 Lec02 and Lec03

The document provides an introduction to C programming, covering essential concepts such as abstraction, the structure of a C program, and key components like header files and functions. It explains the importance of variables, data types, and operators in C, along with guidelines for variable naming and memory allocation. Additionally, it highlights the role of compilers, IDEs, and documentation in the programming process.

Uploaded by

mohsin.islam
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/ 27

EEE103/CSE161

Computer Programming
Lecture 02 and 03: Introduction C programming

Course Instructor:
Sharif Mohd Shams, Lecturer, Dept. of EEE,
Brac University
Email: [email protected]
Understanding Abstraction In
Computer Science
Abstraction is the process of hiding complex details to show only the
essential features.

It helps in managing complexity and makes systems easier to use and


understand.

A real life analogy would a map of a city – it shows roads and landmarks
but hides individual buildings and trees.
Level of Abstraction
Getting Started With C

Return Type Header File

Start of
program
Library Statement
Function

End of
program
Getting Started With C

include”, the # symbol indicates a preprocessor.

This commands for something that has to be


done compilation.

The word “include” means to include the contents


of the header file.
Getting Started With C

<stdio.h> indicates name of the header file.

The header file consists constants, functions and


other declarations.

For different purpose or different functions we


need different library or header file.

You may use ‘help’ or ‘documentation’ to find out


which header file to call for a specific objective.
Getting Started With C
<stdio.h> indicates name of the header file.

The header file consists constants, functions and


other declarations.

For different purpose or different functions we


need different library or header file.

You may use ‘help’ or ‘documentation’ to find out


which header file to call for a specific objective.

stdio.h means standard input output header file,


which is typically necessary for taking inputs and
printing them as output.
Getting Started With C

In 2nd line ‘main()’ is a function, which is


necessary to be called before every C program.

Program starts from the first line of ‘main()’.

The term “int” represents the return type.


Getting Started With C

The curly braces ‘{}’ are like containers of the


code.

The code within an open and closed brace is


known as a block.

In case we miss either braces, the code will not


be compiled and show compilation error, like
“Compound Statement Missing”.
Getting Started With C
The function printf() in included in the header file
stdio.h.
Its function is to print any parameter.
Every statement in C program must end with a
semicolon ‘;’, otherwise it will generate error, like
“Statement missing”.
In the statement “return 0”, the term return
indicates how the program ends/exits.
In this case, if 0 is returned means there was no
error in the code.
Abnormal termination is typically indicated by
non-zero return.
Some Programming Tools

Compiler
Standard Library
IDE (Integrated Development Environment)
Help files and Documentations
Compilers
Match Syntax
Finds errors
Prepare object code to be translated to machine language
Help files and Documentations

Standard Library
Provide implementations of some basic and important functions
Library functions must be used to increase efficiency and portability .
IDE - INTEGRATED DEVELOPMENT ENVIRONMENT

Helps to Write
Use different color to highlight different type of code
Sometimes shows hints

Helps to Compile
Set environment variables
Linking with libraries

Helps to Debug
Execute step by step
Use breaks
Watch the values of variables

Helps to Run the code


Help file and documentations

Provide details about


Syntax
Keywords
Library functions
Examples
Etc.
Some important keywords
C has some words that have special meaning for the
compiler
These words can not be used to name variables, functions
etc.

auto double int struct


break else long switch
case enum register typedef
char extern return union
const float short unsigned
continue for signed void
default goto sizeof volatile
do if static while
Variables
Variables are like containers. They can hold
values.
The values can be of different types: Integer,
Floating point numbers, Characters etc.
Each variable takes up some memory space
The values can be assigned, changed, read etc.
Variables must be declared before using them
VARIABLE DECLARATION AND
INITIALIZATION
First write the keyword for data type
Then write the name of the variable
Example
int num=10;
char c=‘a’;
int i, j, k;
char esc=‘\’;
float exp=3.2e-5;
float sth=3.223;
PRINT VARIABLES
Variable naming system
Variables are case sensitive
Ccc, ccc, cCc & CCC are all distinct variables
May comprise letters, digits and the
underscore
The first character in a variable name cannot
be a digit
Variable name cannot be same as any
keyword
No commas or blanks are allowed within a
variable name
Data types

Basic data types of C-


int (integer / whole number)
float (4 bytes of memory space, 7 digits after the decimal point)
double (8 bytes of memory space, 15 digits after the decimal point)
char (character)
void (used in function prototype example no parameters)
Allocated memory of the data types
Format specifier in C programming which act as a placeholder for an integer
argument in a formatted input and output statement.
Integer: %d

Character : %c

Float : %f

Double : %lf or %f

Unsigned int: %u

String : %s used in character arrays, will get back to it


later

In addition to digits, we have 3 special letters: h, l and L.


h, used with integer numbers, indicates a short int (for example
%hd) or a short unsigned int (for example %hu)
l, used with integer numbers, indicates a long int (for example
%ld) or a long unsigned int (for example %lu).
L, used with floating point numbers, indicates a long double, for
example %Lf
Bitwise Operators
Arithmetic Operators
If value of x = 100 and y = 20

Operator Operation Result


+ (Addition) z=x+y z = 120
- (Subtraction) z=x–y z = 80
* (Multiplication) z=x*y z = 2000
/ (Division) z=x/y z=5
% (Modulus) z=x%y z=0
++ (increment by 1) z = x++ z = 100, x = 101
z = ++x z = 101, x = 101
-- (decrement by 1) z = x-- z = 100, x = 99
z = --x z = 99, x = 99
Logical Operators
Precedence Chart
Thanks

You might also like