chapter 2: c fundamentals dr. ameer ali. overview c character set identifiers and keywords data...

22
Chapter 2: C Fundamentals Dr. Ameer Ali

Upload: clyde-wilkinson

Post on 26-Dec-2015

228 views

Category:

Documents


1 download

TRANSCRIPT

Chapter 2: C Fundamentals

Dr. Ameer Ali

Overview

C Character set Identifiers and Keywords Data Types Constants Variables and Arrays Declarations Expressions Statements Symbolic constants

C Characters

A-Z, a-z, 0-9+, -, &, ^, $, #, @ etc.

Identifiers

Variable: a name given to a value to access using program such as sum_1, x1, y1, etc.

Identifiers are names that are given to various program elements such as variables, functions and arrays.

Identifiers consists of letters and digits in any order except that the first character must be a letter.

Both upper case and lower case letters are accepted, but not interchangeable. Such as: Sum and uSm are two different.

Identifiers

_ can be used.Arbitrarily long, but some C

implementation can use only 8 characters such as file name.

Keywords

Some reserved words that have standard and predefined meaning in C is known as keywords.

Can only use for their intended purpose, not for other use.

The standard keywords are:

auto break case char const do double else

enum for float goto if int long short

signed sizeof static struct switch union void while

Data Types

Data

Types

Description Memory

(Byte)

int

long int

Integer 2 or 1

4

char Single character 1

float Floating point 4

double Double precision floating point 8

Data Types

Int: short, long, signed, unsigned integer Ordinary integer int can carry only -32,768 to

+32767, while unsigned int can 0 to 65535 Char:

One character 0 to 255 signed char can -128 to +127

Double, float can carry large values

Constants

Four types of basic constants: Integers constant Floating point constant Character constants String constants

Integer and floating-point constants are known as numeric constant and can be applied following rules Comma’s and blank spaces can not be included

Constants

Constants can be preceded by – operatorValue can not exceed minimum and

maximum values

Integer Constants

Is an integer valued numbersConsist of sequence of digitsCan be written in three different format:

DecimalOctalHexa decimalExample: D-19278, O-12356, H-987ABC

Floating Point Constants

5.047365.036E-17=5.036*10-17

3.45E5=3.45*105

Character Constants

ASCII: American Standard Code for Information Interchange

Character Constants

Character Constants

EBCDIC: extended binary coded decimal interchange code

Escape Sequences

\ and ‘ can be expressed as escape sequence

Line feed (LF): \nOthers

\t horizontal tab \v vertical tab

\a alert \0 null

\b backspace

String Constants

“abcdefgh”

Variables and Arrays

Variables: used to represent some specific type of information within designated portion of the programA, b, c, abh, xyz.A=3; b=5;

Array: is an identifier that refers to a collection of data items that all have the same name.

Array

12 3 19 50 16 75 18 99

1 2 3 4 5 6 7 9

Index Value

Declarations

Type Name; Int a;Float b;Char c;Double d;

Type Name [Size] Int A[100]

Expression

Statements