O'Reilly logo

Express Learning - Computer Fundamentals and Programming by ITL ESL, Ashok Kamthane

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

The C Declarations
1. What are the different data types?
Ans: C data type is classified as follows:
1. Basic data type: Basic data types are (a) integer (int), (b) character (char), (c) floating point
(float) and (d) double floating point (double).
2. Derived data type: Derived data types are pointers, functions and arrays.
3. User-defined type: User-defined data types are struct, union, enum and typedef.
4. The void data type: It is an empty data set. This data type can be followed from the chapter on
Functions.
2. What are the differences between signed and unsigned data types?
Ans: When a variable is declared as unsigned, the negative range of the data type is transferred
to positive, i.e., doubles the largest size of the possible value. This is due to declaring unsigned int;
the 16th bit is free and is not used to store the sign of the number.
Some differences between signed and unsigned data types are shown in the following table.
signed int unsigned int
Range: −32,768 to 32,767 Range: 0 to 65535
Format %d or %i prints signed integers Format %u prints unsigned integers
For long signed int, range is −2147483648 to 2147483647 For long unsigned int, range is 0 to 4294967295
Format %ld prints long signed integers Format %lu prints unsigned integers
3. What do we mean by a variable and a constant?
Ans: A ‘variable’ is a data name used for storing a data value. Its value may be changed during the
program execution. It has memory location and it can store a single value at a time. The ‘constants’ in C
are applicable to the values, which do not change during the execution of a program.
2
M02_ITL-ESL4791_02_SE_C02.indd 13 12/22/2012 4:59:41 PM
II-14 Programming Concepts
4. Explain different types of constants in C.
Ans: Constants in C are as follows:
1. Numerical Constants
(a) Integer constants: These are a sequence of numbers from 0 to 9 without decimal points or
fractional part or any other symbols. It requires minimum 2 bytes and maximum 4 bytes of
memory. Integer constant could be either positive or negative or may be zero.
Example: -10, 20, +30, -15.
Besides, representing the integers/real constants in decimal number system, they also can be
represented in octal or hexadecimal number system based on the requirement.
(b) Real Constants:Real constants are floating-point constants.
Example: 2.5, 5.521, 3.14.
2. Character Constant
(a) Single character constants:A character constant is a single character (length = 1). It can also
be represented with single digit or a single special symbol or white space enclosed within a
pair of single quote marks.
Example: 'a', '8', '-'.
(b) String constants:String constants are a sequence of characters enclosed within double quota-
tion marks.
Example: "Hello", "India", "444", "a".
5. How the octal and hexadecimal numbers represented in C?
Ans: Numbers or constants can be represented in octal or hexadecimal based on the requirement/
applications.
Octal has base 8 and hexadecimal has base 16. The octal numbers are 0, 1, 2, 3, 4, 5, 6, 7 and hexa-
decimal numbers are 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F.
The representation of octal numbers in C would be done with leading digit 0 and for hex representa-
tion with leading 0X.
Following are a few examples of octal and hexadecimal numbers.
027, 037, 072 – Octal numbers
0X9, 0Xab, 0X4 – Hexadecimal
6. What are the C keywords? Elaborate them.
Ans: The C keywords are reserved words by the compiler having fixed meaning. They cannot be
used as a variable name. The 32 C keywords provided in ANSI C are listed in the following table.
auto double int struct
break else long switch
case enum register typedef
char extern return union
const float unsigned short
continue for signed void
M02_ITL-ESL4791_02_SE_C02.indd 14 12/22/2012 4:59:41 PM

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required