Download presentation
Presentation is loading. Please wait.
1
ASST. Prof. Dr. Hacer Yalım Keleş
COM101B Lecture 1: BASICS ASST. Prof. Dr. Hacer Yalım Keleş Reference: “Programming in ANSI C”, Kumar & Agrawal, West Publishing Co., 1992
2
The sequentıal structure
Entry -> Statement 1 -> Statement 2 -> ... -> Statement N -> Exit Example Program: #include <stdio.h> int main() { printf(«Knowledge is power\n»); return 0; } Reference: “Programming in ANSI C”, Kumar & Agrawal, West Publishing Co., 1992
3
CHARACTER SET The set of characters that may appear in legal C programs is called the «character set» for a language. This may include graphic and non-graphic characters Graphic characters: that may be printed Non-graphic characters: represented by escape sequences, i.e. \n, \t, etc. There is also a null character: \0 Reference: “Programming in ANSI C”, Kumar & Agrawal, West Publishing Co., 1992
4
Reference: “Programming in ANSI C”, Kumar & Agrawal, West Publishing Co., 1992
5
C compiler groups characters into tokens:
The graphic characters, other than decimal digits, letters and blank are called special characters Blank, horizontal and vertical tabs, newlines and formfeeds are called whitespace characters C compiler groups characters into tokens: A token is a sequence of one or more characters that have a uniform meaning Some tokens are one char long, i.e. /,*,+,> etc. Some tokens are sevaral char long, i.e. ==, >=, comments, variable names etc. When collecting characters into tokens, the compiler always performs the longest possible tokens. Reference: “Programming in ANSI C”, Kumar & Agrawal, West Publishing Co., 1992
6
C is a free-format language:
tokens can go anywhere on a page Tokens can be separated by any number of whitespaces. The program below: int main() { printf(«Hello»); } Is equivalent to: int main(){printf(«Hello»); } Reference: “Programming in ANSI C”, Kumar & Agrawal, West Publishing Co., 1992
7
Data types Data is differentiated into types: Built-in data types:
The type of a data element restricts the set of values that the data element can take. Built-in data types: char: a character in the C character set int: an integer float: a single-precision floating point number double: a double-precision floating point number Some extensions: short int, long int, long double Reference: “Programming in ANSI C”, Kumar & Agrawal, West Publishing Co., 1992
8
The qualifiers signed and unsigned can be applied to:
char, short int, int, or long int. unsigned variables: can only have non-negative values. signed variables: can have both positive and negative values. In the absence of explicit usigned specification; int, long int, or short int are considered as signed. Reference: “Programming in ANSI C”, Kumar & Agrawal, West Publishing Co., 1992
9
SIGNED REPRESENTATIONS
Ones’ Complement Representation (8 bits): Binary value Ones’ Complement Interp. Unsigned Interpret. Reference: “Programming in ANSI C”, Kumar & Agrawal, West Publishing Co., 1992
10
SIGNED REPRESENTATIONS
Two’s Complement Representation (8 bits): Binary value Two’s Complement Interp. Unsigned Interpret. Reference: “Programming in ANSI C”, Kumar & Agrawal, West Publishing Co., 1992
11
The widths of the datatypes are not specified by the C language, yet many implementations represent
a char in 8 bits, a short in 16 bits, an int in 16 or 32 bits, a long in 32 bits C specifies that: the range of int may not be smaller than short, the range of long may not be smaller than int, the long double is at least as precise as a double a double at least as precise as a float The particular bit widths of an implementation are specified in: <limits.h> and <float.h> header files. Reference: “Programming in ANSI C”, Kumar & Agrawal, West Publishing Co., 1992
12
Types cntd. Integral types: Floating-point types: Arithmetic types:
all types of integers and characters Floating-point types: float, double, long double Arithmetic types: Integral and floating point types Reference: “Programming in ANSI C”, Kumar & Agrawal, West Publishing Co., 1992
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.