Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Objectives
After this Session, you will be able to identify C tokens know C key words and identifiers write constants and variables of C language
Introduction
The C programming language was designed by Dennis Ritchie at Bell Laboratories in the early 1970s Influenced by ALGOL 60 (1960), CPL (Cambridge, 1963), BCPL (Martin Richard, 1967), B (Ken Thompson, 1970)
Standard C
Standardized in 1989 by ANSI (American National Standards Institute) known as ANSI C International standard (ISO) in 1990 which was adopted by ANSI and is known as C89 As part of the normal evolution process the standard was updated in 1995 (C95) and 1999 (C99)
Elements of a C Program
A C development environment includes
System libraries and headers: a set of standard libraries and their header files. Application Source: application source and header files Compiler: converts source to object code for a specific platform Linker: resolves external references and produces the executable module
Elements of a C Program
User program structure
there must be one main function where execution begins when the program is run. This function is called main int main (void) { ... }, int main (int argc, char *argv[])
{ ... }
Header files
The files that are specified in the include section are called as header files These are precompiled files that have some functions defined in them We can call those functions in our program by supplying parameters Header file is given an extension .h C Source file is given an extension .c
Main function
This is the entry point of a program When a file is executed, the start point is the main function From main function the flow goes as per the programmers choice. There may or may not be other functions written by user in a program Main function is compulsory for any c program
Running a C Program
Type a program Save it Compile the program This will generate an exe file (executable) Run the program (Actually the exe created out of compilation will run and not the .c file)
CHARACTER SET
C characters are grouped into the following categories.
1. 2. 3. 4. Letters Digits Special Characters White Spaces
Special characters
, Comma . Period ; Semicolon : Colon ? Question mark Apostrophe Quotation mark ! Exclamation | Vertical Bar / Slash \ Back slash ~ Tilde _ Underscore $ Dollar sign % Percent sign & Ampersand ^ Caret * Asterisk - Minus + Plus sign < Less than > Greater than ( Left parenthesis ) Right parentheses [Left bracket ] Right bracket { Left brace } Right brace # Number sign
C TOKENS
In C programs, the smallest individual units are known as tokens.
Comments in C
Single line comment
// (double slash) Termination of comment is by pressing enter key
Structure of C program
/* This is a comment */ // This is a one-line comment # include <stdio.h> /* includes header files */ main() /* Must have a main function. First function executed */ { printf ("Hello World!"); /* stdio functions */ }
Variables
Variables are data that will keep on changing Declaration
<<Data type>> <<variable name>>; int a;
Definition
<<varname>>=<<value>>; a=10;
Usage
a=a+1; //increments the value of a by 1
CONSTANTS
Constants in C refer to fixed values that do not change during the execution of a program.
CONSTANTS
Integer Constants
An integer constant refers to a sequence of digits, There are three types integers, namely, decimal, octal, and hexa decimal.
Decimal Constant
Eg:123,-321 etc., Note: Embedded spaces, commas and non-digit characters are not permitted between digits. Eg: 1) 15 750 2)$1000
Octal Constant
An octal integer constant consists of any combination of digits from the set 0 through 7, with a leading 0. Eg: 1) 037 2) 0435
Hexadecimal Constant
A sequence of digits preceded by 0x or 0X is considered as hexadecimal integer. They may also include alphabets A through F or a through f.Eg: 1) 0X2 2) 0x9F 3) 0Xbcd
Real Constants
Certain quantities that vary continuously, such as distances, heights etc., are represented by numbers containing functional parts like 17.548.Such numbers are called real (or floating point)constants. Eg:0.0083,-0.75 etc., A real number may also be expressed in exponential or scientific notation. Eg:215.65 may be written as 2.1565e2
C supports special backslash character constants that are used in output functions. These character combinations are known as escape sequences.
Summary
In this lesson we learnt described character set learnt the C tokens studied about constants variables of C
and