Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Part 2
Constant and Identifier
Data Types
Pre-processor Directives
2
CHAPTER 2
Introduction to C Language
• What is C language?
3
CHAPTER 2
Introduction to C Language…cont.
• Advantages of C language:
5
Comment in Program
Programmers can make a program easier to understand
by using comments
This is to describe the purpose of the program, the use
of identifier and the purpose of each program step
Comments are part of the program documentation
because it help others read and understand the program
Compiler will IGNORE the comments and there are not
translated into machine language.
In C a comment will start with /* and ends with */
6
CHAPTER 2
• Example Comment of Program
/* This is a multiline
* comment in C */
/****************************************************
* This style of commenting is used for functions
****************************************************/
7
CHAPTER 2
Questions
1) C programs are converted into machine
language with the help of?
a) An Editor
b) A compiler
c) An operating system
d) None of the above
Answer:
8
CHAPTER 2
Questions
2) What is the error?
/* This is a multiline
* comment in C /
/****************************************************
* This style of commenting is used for functions
****************************************************/
Answer:
9
CHAPTER 2
Basic C
10
CHAPTER 2
Library File
• E.g : #include <stdio.h>
• Typically, include files are library files, also called header files,
that are provided by the language compiler
#include <stdio.h>
return 0;
}
Variables (1 of 2)
Function Variable
• The function of variable is to hold the data in your program
int b;
printf("%d", b);
14
CHAPTER 2
Variable Names
In C all the variables should be declared before it can be used.
16
CHAPTER 2
•Some examples of valid (but not very descriptive) C
variable names:
uthm
Uthm
UTHM
parit_raja
_uthm42
_
UtHm
int age;
int age, count, i,j;
float amount, rateOfInterest, totalBalance;
char ch;
18
CHAPTER 2
Question
1) A C variable cannot start with
a) An alphabet
b) A number
c) A special symbol other than underscore
d) both (b) and (c) above.
Answer:
19
CHAPTER 2
Common Errors
• Starting a comment line with /* but forgetting
to terminate it with */
• Placing a space between / and *, such as / *
• Using uppercase letters with the C keywords,
such as Printf
• Forgetting the ; (semicolon) at the end of each
statement
• Placing a semicolon at the end of a preprocessor
command, such as # include <stdio.h>;
• Placing a semicolon at the end of a function
header, such as int main ();
End of Part 1
Thank you !
21
CHAPTER 2
output :?
23
CHAPTER 2
Type of Constants
Integer Constant
An integer constant must have at least one digit and
should not have decimal point.
It could either be positive or negative.
Example:
const int MAX_NUM = 10;
const int MIN_NUM = -90;
const int Hexadecimal_Number = 0xf87;
24
cont.
• Real Constant
• A real constant must have at least one digit and must
have a decimal point.
Example:
0.0026
-0.97
435.29
+487.0
25
cont.
Character Constant
A character constant should be only one character and must
be enclosed in single quotes e.g. ‘A’, ‘b’, etc.
Example:
const char letter = ‘n’;
const char number = ‘1’;
printf(“%c”, ‘S’);
Output would be? ___
26
Identifier
27
cont.
• Two rules must be kept in mind when naming
identifiers.
28
Data Types
• Data type is a set of values and a set of operation on those values.
• The 4 basic data type are as below:
– Int
• To represent integers in C
• -10500, 435, +15, -25, 34728
• int some_number=3;
– Double
• To represent real numbers in C
• 3.14159, 0.0005, 150.00
– Char
• To represent an individual character value in C
• A letter, a digit or special symbol
• ' B ', ' C ', ' * ', ' : ', ' “ '
• Object of data type can be variables or constants
29
CHAPTER 2
30
Preprocessor Directives
Preprocessor Directives is a message from
programmer to the preprocessor.
It is a unique feature of C language.
A program can use the tools provided by
preprocessor to make his program easy to
read, modify, portable and more efficient.
Preprocessor directives follow the special
syntax rules and begin with the symbol #bin
column1 and do not require any semicolon at
the end. A set of commonly used preprocessor
directives.
30
CHAPTER 2
Directive Function
31
End of Part 2
Thank you !
32