Sunday 1 January, 2012

II. OVERVIEW



II. OVERVIEW


Short Answers

1. Who developed C++ language?
C++ was developed at AT & T Bell laboratories in the early 1980s by Bjarne Stroustrup.
2. Who coined the name C++?
The name C++ was coined by Rick Mascitti where ++ is the C increment Operator
3. What do you mean by the term TOKEN in C++?
  • The basic types of elements are collectively called as TOKENS.
  • The token is the smallest individual unit in a program.
  • Tokens are classified as keywords, identifiers, constants, operators and punctuators
4. What are keywords in C++?
  • Keywords have special meaning to the language compiler.
  • These are reserved Words for special purpose.
  • These words cannot be used as normal identifiers.
Ex.auto,break,case,const,class,for,if etc..
5.List a few of the keywords in C++.
Auto, break, case, const, class, default, static, switch, while, if etc..
6. What is meant by Identifiers?(or)What are variables? Ex.
  • Identifiers are also called as variables.
  • Variables are memory boxes that hold values or constants.
  • A variable name must begin with an alphabet or underscore(_) followed by alphabets or numbers.
Ex: _AB, AB, AB4
7.What are the rules to be followed while writing variable name?
  • A variable name must begin with an alphabet or underscore(_) followed by alphabets or numbers.
Ex: _test; test; sum 12
8. What are constants?
Constants are data items whose values cannot be changed.
There are two types of constant ,They are
  • Numeric constant
  • Non-Numeric constant
9. What are numeric constants?
Numeric constant consists of only numbers either whole numbers or decimal numbers. There are two types, 1. Integer 2.Floating-point
10. What is Integer constant?
  • Integer Constant must have at least one digit and must not contain any fractional part
  • May be prefixed with a + or - sign.
11. How is the octal integer constant treated? Give example.
A sequence of digits starting with 0 (zero) is treated as Octal constant. Ex: 010= 8(dec.)
12. How is the Hexadecimal integer treated? Give example.
A sequence of digits starting with Ox is treated as hexadecimal integer. Ex: 0xF= 15 (dec.)
13 .What is a Floating point constant? Give example.
  • Floating Point Constant is a signed real number.
  • It includes integer portion, a decimal point ,fractional portion and an exponent
  • While representing a floating point constant,
The integer portion or the Decimal portion can be omitted but never both. Ex. 28.31
14. How is the given number represented in exponent form
(a) 5.864 x 101 (b) 5864 x 10-2 and (c) 0.5864 x 102
(a) 5.864 x 101 = 5.864 E 1
(b) 5864 x 10-2 = 5864 E -2
(c) 0.5864 x 102 = 0.5864 E 2
15. What is character constant?
  • Character constant is a constant that contains a single character
  • Enclosed within single quotes. ()
  • It can be any character as define the character set of C++.
16. What are non-graphic character constants?
  • Certain special characters like tab, backspace, line feed, nulls ,backslash are called as non-graphic character constants.
  • These characters are represented using escape sequences.
  • Escape sequences are represented using characters prefixed with a backslash. (\) Ex. \a,\n,\b etc…
17. List out the non-graphic character and its escape sequence.
Escape Sequence Non graphic Character
\a Bell
\b Back space
\n New line/ line feed
\t Horizontal tab
\v Vertical tab
\\ Back slash ­ or
\" Single / double quotes
\o Octal number
\x Hexadecimal number
\0 Null
18. What is String Literal? Give example.
  • String Literal is a sequence of characters surrounded by double quotes. (“)
  • String literate are treated as an array of characters.
  • Each string literal is by default added with a special Character '\0' which marks the end of string. Ex. “school”
19.What are the reasons in which Data is grouped into different categories?
*)The compiler may use the proper internal representation for each data type
*)The programmer designing the programs may use appropriate operators for each data type.
20.What are the classification of data type in C++?
They can be broadly classified into the following three categories.
User defined type
Built-in type
Derived type


21.What is an operator and an opened? Give suitable examples
  • Operator specifies an operation to be performed that yields a value.
  • An operand is an entity on which an operator acts.
For example
Sum = A+B
  • A and B are operands
  • + is the operator that performs the addition of the numbers.
  • The result is stored in the variable “Sum “ by "="(Assignment) operator.
22. What are the operators used only by the preprocessor?
The operators # and ## are used only by- the preprocessor
23.What are the operators specific to C++?
  1. :: 2) .* 3) ->*
24.How are the operators classified?
Operators are classified as
  1. Arithmetic,
  2. Assignment,
  3. Component Selection,.
  4. Logical,
  5. Manipulator,
  6. Member dereferencing,
  7. Memory Management,
  8. Preprocessor,
  9. Relational,
  10. Scope Resolution,
  11. Shift and
  12. Type Cast.
25.How are the operators classified based on operand requirements?
Based on operand requirements, operators are also classified as
  • Unary operators-operates on one operator
  • Binary operators-operates on two operators
  • Ternary operators-operates on three operators.
26. What is unary operator?
Unary operator operates on one operand.
27. List out the unary operators?
  • & Address of
  • ! Logical Not
  • * Indirection
  • ++ Increment
  • ~ Bitwise
  • -- Decrement
  • - Unary minus
  • + Unary plus
28 .Give the list of Additive binary operator?
Additive binary operator are + Binary Plus - Binary minus
29.List out the multiplicative binary operator
Multiplicative binary operator are . * Multiply / Divide % Remainder (Modulus)
30. What are the shift binary operators?
Shift binary operators are
<< Shift Left and >> Shift Right
31. What are the Bitwise binary operators?
Bitwise binary operators are
1) & AND 2) | OR 3) ^
32. List out the logical binary operators?
Logical binary operators are
&& Logical AND
|| Logical OR
33.Give the list for Assignment binary (Shorthand)operators? (or) What are shorthand assignment operator?
Assignment binary operators are
  1. = Assignment
  2. /= Assign quotient
  3. += Assign sum
  4. *= Assign product
  5. %= Assign remainder
6) - = Assign difference
  1. <<= Assign left shift
  2. >>= Assign right shift
  3. &= Assign bitwise AND
  4. ^= Assign bitwise XOR
  5. |= Assign bitwise OR
34. What are Relational operators?
  • Relational operators are used to compare numeric values.
  • A reconstructed using any two operands connected by a relational operator
  • The result of a relational operation is returned as true or false.
  • The numeric constant zero(0) represents False value
  • The numeric constant zero(1) represents True value
Relational operators are
< Less than
> Greater than
<= Less than or Equal to
>= Greater than or Equal to
== Equal to
!= Not Equal to
35. What is equality operators ?
Equality operators are = = Equal to ! = Not Equal to
36. What are component selection and class member binary operators?
Component selection, binary operators are
. Direct component selection
-> Indirect component selection
Class member binary operators are
:: scope access/Resolution operator .
· * Dereference operator
->* Dereference pointer to class member.
37. What are arithmetic operators?
  • Arithmetic Operators are used to perform mathematical operations.
  • Arithmetic expressions are formed using arithmetic operators
The list of Arithmetic Operators are:
+ Addition operator
- subtraction operator
* multiplication operator
/ division operator
% modulus operator
+=,-=,*=,/=,%= Arithmetic Assignment
38. What is an association?
  • Operators are executed in the order of precedence.
  • The operands and the operators grouped in a specific logical way for evaluation.
  • This logical grouping is called as association
39. What are logical operators? Give an example.
  • Logical operators combine the results of one or more conditions.
  • The various logical operators are
&& (AND), || (OR), ! (NOT)
Example: c = 5, d = 6, choice =’y’, term = 2 (Assume True is indicated as 1 False as 0).
Result = (c = =d) && (choice ! = term) The values stored in Result is 0 (False);
40. What are conditional operators? Give its syntax
A ternary operator ?: is also called as conditional operator.
Syntax : E1?E2:E3
  • E1,E2,E3 are operands
  • E1 should be of scalar type ( condition)
  • E2 and E3 are values or statements.
Example. A = (x > y)? M: N
If x > y True then the value of M is assigned to A
Otherwise the value of N is assigned to A
41.What are the assignment operator?
  • Assignment operator = is the simple assignment operator
  • It is used to assign the result of an expression to the variable.
  • There are 10 ‘shorthand ‘assignment operators
42.What are Data types?
The kind do data that variables hold in a programming language is called the DATA TYPES.
They can be broadly classified into the following three categories.
  • User defined type,
  • Built-in type and
  • Derived type.
43.How does the user defined data type help the user? Define user defined data types?
  • User Defined Data Type enables a programmer to invent his/her own data type and define values
  • This helps in improving readability of the program.
  • Ex .Structure ,Union ,class ,enumeration
44.Write the system of Type Definition. Or Give an example and state the user defined data type identifiers.
typedef ia a user defined data type.
typedef helps in creating meaningful data type identifiers,
It helps to increase the readability of the program.
The syntax:
typedef <data_type> <user_defined_data_type_identifier>;
For example:
typedef int marks;
marks is a user defined data type identifiers for int
Users can define variables of int
marks eng_marks, math_marks;
45.Define enumerated data type
  • enum is a user defined data type.
  • It helps to create a list of identifiers,
  • also called as symbolic numeric constants of the type int.
The syntax :
enum <data type identifier> (value 1, value 2, … value n);
Ex. enum days (Monday, Tuesday);
days – user defined data type.
Monday , Tuesday – Values or enumeration constants
To declare variables
syntax :
enum identifier variable1, variable2 …,variable n;

days firstday,secondday;
firstday = Monday;
secondday = Tuesday;
46.What is storage class and how many storage specifiers are there?
  • Storage Class is another qualifier (like long or unsigned) that can be added to a variable declaration.
  • They are auto, static, extern and register.
47.What values are taken by the Static, Register and Auto variables? When are they declared?
  • Static and Register variables are automatically initialized to zero when they are declared.
  • Auto variables are not initialized with appropriate values based on their data type.
48.When is the variable called as garbage? Or Define Auto
  • Auto variables are not initialized with appropriate values based on their data type.
  • By default the local variables are auto
  • When these variables get undefined values known as garbage.
49.Define static storage class.
  • Static variables are automatically initialized to zero when they are declared
  • Static modifier allows the variable to exist in the memory of the computer, even the function or block exist its scope.
  • Hence ,the variable also retains the last assigned value
50.Define Register storage class.
  • Register variables are automatically initialized to zero when they are declared
  • The register instructs the compiler to store the variable in the CPU register to optimize access.
51..Define extern storage class.
  • Global variable known to all functions in the current program.
  • These variables are defined in another program
52.What is Built in Data Type?
Built in Data Type is also called as Fundamental or Basic data type.
They are predefined in the compiler.
Integral, Float and Void are the three fundamental data types
53.What are the divisions in integral type?
The divisions in Integral type are int and char.
Int is the integer data type.
It cannot hold fractional values.
Char is character data type that can hold both the character data and the integer data.

54.What are the divisions in floating type?
Floating type is divided into float and double.
Floating type can store values with fractional part.
55.What is the use of void type? Define void data type.
Void data type has two important purposes:
To indicate that a function does not return a value.
To declare a generic pointer.
56.What are the derived data type?
Derived Data Type are built form the basic integer and floating type (built in type) or user defined data types
Ex. array, function, pointer and reference
57.What is an address?
  • Every byte in the computer’s memory has an address.
  • Addresses are numbers.
The address number starts at NULL and go up from there.. 1,2,3……..
58.What is the minimum and maximum address value for 640 kb memory size?
A memory size of 640 Kb will have addresses commencing from NULL and goes upto 655, 359.
59.How does the memory allocated to the variable by the compiler?
  • When a program is compiled, memory is allocated to the variables by the compiler.
  • The amount of memory allocated to each variable depends on the data type of the variable.
For example consider the declarations.
char c; int i; float f;
char c - 1 byte , int I - 2 bytes , float f - 4 bytes
60.What are the important operators in pointer data type?
The important operators are the address of (&) operator and the value at operator (*).
61.State the reason for declaring the variable initially. Write declaration syntax
  • Variable are allocated memory to store data.
  • Compiler allocates memory, based on the data type of the variable.
  • Hence variables must be declared before they are used.
Syntax:
<Data type> space <variable1,variable2…>;
62.What are the uses of *(asterix)?
1) Used to declare a pointer variable
2) Used to display the contents stored at a location ( value at the address operator )
3) It is a unary operator
63.How many words are there for data types and what are they?
There are nine words for data types such as char, int, double, float, void, short, signed, lone and unsigned.
64.How many bits are used to store integer values?
  • Integer values are stored in16 bit format in binary form.
  • Starting from right extreme, 15 bits are used to store data.
  • 16th bit, also called as the most significant Bit or sign bit
  • The 16th bit will have a value 1 if negative value is stored.
75.What is the maximum and minimum value stored in an Integer variable?
Maximum value stored in an integer variable is +32767 and the minimum value is –32768,
as 215 is 32767 on the positive side and – 32768 on the negative side.
76.Define modifiers.
  • The modifier alerts the base data type to yield new data type
  • Prefix the data type with modifiers at the time of declaring variables.
The impact of modifiers
Unsigned modifiers the range of the integer values as the sign bit is also used to store data.
Long increases the bytes for a particular data type, thus increasing the range of values.
Ex. unsigned int a; long int a;

77.What is the length and range of unsigned char and char data types?
Type Length Range
unsigned char 8 bits 0 to 255
char 8 bits -128 to 127
78.What is the length and range of enum, unsigned int, short int and int data types?
Type Length Range
enum 16 bits -32,768 to 32, 767
unsigned int 16 bits 0 to 65,535
short int 16 bits -32, 768 to 32,767
int 16 bits -32, 768 to 32, 767
79.What is the length of unsigned long, long, float, double and long double data types?
Range Type Length
unsigned long 32 bits 0 to 4,294, 967,295
long 32 bits -2,147,483, 648 to 2,147, 3.4 * (10** -38) to 3.4 * (10** + 38)
double 64 bits 1.7 * (10** -308) to 1.7 * (10** + 308)
long double 80 bit 3.4* (10** -4932) to 1.1 * (10** + 4932)
80.How are the pointer variables declared?
  • A pointer is a variable that hold a memory address.
  • Pointer provides the means through which the memory location of a variable can be directly accessed.
  • There are two operators that deals with pointer.
  • They are address of ( & ) and the value at operator (*)
Ex. int * iptr;
iptr - Name of the pointer variable
* - Instructs compiler that the variable is pointer (it will hold an address)
Int - Indicates that the pointer will point to data type
The addresses stored in pointer variables should be of the same data type a pointer variable is pointing to.
For example:
int * iptr, num1;
num1 = 10;
iptr = &num 1;

81.What is the meaning of implicit conversion?
  • Implicit conversions, refers to data type changes brought about in expressions by the compiler.
For example consider the following snippet.
float f = 7.6;
int x = f;
Now x is 7, as float is converted to int.
The compiler does this conversion automatically.
82.What is the use of sizeof in an operator?
  • sizeof is an operator.
  • It returns the size (memory requirement) in terms of bytes, of the given expression or data type.
ex. sizeof(variavble);
83.What will happen when pointer variable and addressing variable differ?explain with an example.
Compiler shows an error
Ex. int * iptr;
float num1 = 10.5;
iptr = &num 1; / / initializing pointer variable pointing to integer data type with the address of float variable would throw an error.
84.What is type cast and its syntax
  • Type cast refers to the process of changing the data of the value stored in a variable.
  • Type cast is achieved prefixing the variable or value with the required data type.
  • The syntax is:
  • (data type) <variable /value> or data type (variable / constant)
Ex. (int) 7.8
85.Define Pointer variable
  • A pointer is a variable that hold a memory address.
  • Pointer provides the means through which the memory location of a variable can be directly accessed.
  • There are two operators that deals with pointer.
  • They are address of ( & ) and the value at operator (*)


Book Exercises:
1.Determine the order of evaluation of the following expressions:

2.Identify errors in the following programs.
Errors in Programs:
(a) 1. FLOAT – lower case letter to be used as float.
2. The variable x not declared its data type. It must be an integer.
(b) same as a
(c)values of x,y,k,l are not initialized .



3.
Predict the output:
(a) 22 21 21
(b) 3
(c) 3
(d) 4
(e) b



4.Evaluate the following C++ expressions.
Answer:
(a) f = 5
(b) c = 10
(c) x =12
(d) y = 1
(e) (i) x = 10, y = 5, z = 11 (10, 5, 11 are integers)
Ans:1
(ii) x = 10, y = 10, z = 2.
Ans:1
(iii) x = 9, y = 10, z = 2.
Ans:1
5.Write C++ equivalent expressions using the conditional operator. Where
(i) f = 0.5 if x = 30, otherwise f = 5
(ii) fn = 0.9 if x> = 60, otherwise. 7
Ans. (i) x = 30 ? f = 0.5 : f = 5;
(ii) x > = 60 ? fn = 0.9 : fn = 0.7;
6.What are pointer variables?
Ref. SA
7.Write a declarative statement to declare ‘name’ as a pointer variable that stores the address pointing to character data type.
char*name;
char n [20];
name = &n;

No comments:

Post a Comment