[go: up one dir, main page]

0% found this document useful (0 votes)
49 views7 pages

Constants Variables and Data Types

This document discusses constants, variables, data types, and tokens in C programming. It covers: 1) Character sets and tokens used in C like keywords, identifiers, special symbols, and strings. Tokens are the individual words and punctuation in a program. 2) Constants in C including numeric constants (integers, reals, octal, hexadecimal), character constants, and string constants. Variables in C must follow naming rules and can store changing values. 3) C supports primary data types like integers (short, int, long), characters, and floating-point numbers (float, double). It also discusses the ranges and precision of different data types.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
49 views7 pages

Constants Variables and Data Types

This document discusses constants, variables, data types, and tokens in C programming. It covers: 1) Character sets and tokens used in C like keywords, identifiers, special symbols, and strings. Tokens are the individual words and punctuation in a program. 2) Constants in C including numeric constants (integers, reals, octal, hexadecimal), character constants, and string constants. Variables in C must follow naming rules and can store changing values. 3) C supports primary data types like integers (short, int, long), characters, and floating-point numbers (float, double). It also discusses the ranges and precision of different data types.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

September 10,

2020 CONSTANTS, VARIABLES & DATA TYPES


CHARACTER SET
 The characters that are
used to make words,
numbers and expressions depend on the computer in which the program is run.
 However, the subset of character already present in personal, micro, mini, mainframe computers. The
characters are classified as
 Letters.
 Digits.
 Special symbols.
 White spaces.
 The compiler ignores whitespaces unless it is a string constant. Whitespace maybe used to separate
words but prohibited in keywords & identifiers
LETTERS DIGITS
Uppercase: A-Z All decimal digits
Lowercase: a-z 0………..9
SPECIAL SYMBOLS
, comma % percent sign
. period & ampersand
? question mark > close angle bracket
‘ apostrophe < open angle bracket
| vertical bar [ left bracket
/ slash ] right bracket
\ back slash $ dollar sign
; semicolon ^ caret
: colon * Asterisk
“ quotation mark ( left parenthesis
! exclamation mark ) right parenthesis
~ tilde { left brace
_ underscore } right brace
# number sign WHITE SPACES + plus sign
Blank space
Horizontal tab
Carriage return
Newline
Form feed
September 10,
2020 CONSTANTS, VARIABLES & DATA TYPES
C TOKENS
 In a passage of text individual words, punctuation marks are called c tokens. Each and every individual is
called c token. And they are of 6 types.
C TOKENS

KEYWORDS
CONSTANT KEYWORDS IDENTIFIERS SPL SYMBOLS STRINGS OPERATORS
 Every c word is classified as a keyword and identifiers. all the keywords have fixed meaning and the
value of it cannot be changed.
IDENTIFIERS
 All the keywords should be written in lowercase letters.
 Identifiers refer to the names of variables functions arrays.
 These are user defined names, and consist of sequence of letters, digits, with first characters as a letter.
 Both uppercase and lowercase letters can be used, although lowercase letters are commonly used.
 The underscore character is also permitted in identifiers; it is usually used as a link between two words
in long identifiers.
RULES FOR IDENTIFIER
1. First character should be an alphabet or underscore can be used.
2. Must only contain letters, digits, or underscore.
3. Can’t use keyword.
4. Only 31 characters are included.
CONSTANTS
5. Must not contain white space.
 Constant in a c refers to the fixed value that doesn’t change during the execution of a program. C
supports several types of constant as illustrated below.
CONSTANTS

NUMERIC CONSTANT CHARACTER CONSTANT

INTEGER CONSTANT
INTEGER CONSTANT REAL CONSTANT SINGLE CHARACTER STRING CONSTANT

 It refers to the sequence of digits. There are three types of integer constant namely.
1. Decimal constant
2. Octal constant
3. Hexadecimal
 Decimal integer refers to digits from 0-9, preceded by negative or positive sign valid.
Eg: -331, 222, 931, and 432
 Embedded spaces, commas, and non digit character are not permitted digits.
Eg: 15750, 20,000 $1000 are illegal numbers.
 An octal integer refers to any combination of numbers from 0-7, leading with 0.
 The numbers preceding OX or ox are called as Hexadecimal numbers. They may contain alphabet also
from A through F or a through f.
 The alphabet from A through F or a through f represents the number from 10-15.
Eg: OX2, OX9F, OXBCD, OX
REAL CONSTANT
 Integer numbers are inadequate to represent quantities that vary continuously such as distances,
heights, temperatures, prices and so on. These quantities are represented by number containing
fractional parts like 17.548.
 Such numbers are called real(floating point) constants further
0.0083, -0.75, 435.36
 A real number may also be expressed in exponential (scientific) notation.
SINGLE CHARACTER CONSTANT
 In exponential notation as the power increases it number of zero increases
 A single character constant contains a single character enclosed with single quotation marks.
Eg: ‘5’ ‘x’ ‘’
 Note that the character constant ‘5’ is not same as the number 5, the last constant is a blank space.
 Character constants have integer values known as ASCII value.
For Eg: the statement printf (“%d”, ‘a’);
Would print the number 97, the ASCII value of letter a. similarly, the statement printf (“%c”, ‘97’);
Would output the letter ‘a’.

STRING CONSTANT
 A string constant is a sequence of characters enclosed in double quoted marks. It can contain letters,
digits, blank spaces etc
Eg: “hello” “123” “x”
BACKSLASH CHARACTER CONSTANT
 C supports some special backslash character constant that are used in output functions
Eg:
‘\a’ audible alert
‘\b’ backspace
‘\f’ form feed
‘\n’ new line
‘\r’ carriage return
‘\t’ horizontal tab
‘\v’ vertical tab
‘\?’ question mark
‘\’’ single quote
‘\’’’ double quote
‘\\’ backslash
‘\0’ null
VARIABLE
 A variable is a dataname that may be used to store a data value, unlike constants that remains
unchanged during the execution of a c program.
 Variable can be created by the programmer so as it reflects its function/nature in the program.
 A variable take variable at different
RULE FOR VARIABLE
1. A variable should begin with a letter, and some system support underscore as 1 st character.
2. A variable should consist 31 character are significant. Only first 31 characters are included.
3. A variable can consist of uppercase and lowercase letters.
4. White spaces are not allowed in variables.
5. A variable shouldn’t be a keyword.
DATA TYPES
 Definition is to be written from google
 ANSI C supports three classes of data types
1.Primary data type
2.Derived data type
3.User defined data type
 All the c compilers support five fundamental data types namely integer (int), character (char), floating
point (float), double-precision floating point (double) and void.
 Many of them also offer extended data types such as long int and long double
PRIMARY DATA TYPES

INTEGRAL TYPE

INTEGER CHARACTER

SIGNED UNSIGNED TYPE CHAR

INT UNSIGNED INT SIGNED CHAR

SHORT INT UNSIGNED SHORT INT UNSIGNED CHAR

LONG INT UNSIGNED LONG INT

FLOATING POINT TYPE

FLOAT DOUBLE
DATA TYPE RANGE OF VALUES
LONG DOUBLE VOID
CHAR -128 TO 127
INT -35,768 TO 32,767
FLOAT 3.4e-38 TO 3.4e+38
DOUBLE 1.7e-308 TO 1.7e+308

INTEGER TYPES

 Integers are the whole numbers with a range of values supported by a particular machine.
Generally integers occupy one word of storage, and since the word sizes of machine vary
( typically 16 or 32 bits).
 The size of the integer that can be stored depends on the computer.
 C has three classes of integer storage, namely short int, int and long int , in both signed and
unsigned forms.

FLOATING POINT TYPES


 Floating point (or real) number are stored in 32 bits, with 6 digits precision. Floating point
numbers are defined in c by the keyword float
 When the accuracy provided by the float number is not sufficient, the type double can be
used to define the number.
 A double type number uses 64 bits giving a precision of 14 digits.
 These are known as double precision numbers.
 Remember that double type represents the same data type that float represents, but with
a greater precision to extend the further,
 We may use long double which uses 80 bits

FLOAT

DOUBLE

LONG DOUBLE

You might also like