Class XI :C++ Review of Chapter 3,4 and 5 Define the following terms : Identifier: An identifier is userdefined name given to any variable ,class,object ,function etc. It is an unlimited sequence of characters consist of letter, digits or underscore. The first character is either (underscore or letter) and an identifier cannot be a reserved keyword like new. Keywords: Keywords are the words whose meaning is already defined to the c compiler. The keywords are also known as “reserved words” . Literals: Literals (also known as constants) are expressions with a fixed value. These are the data items whose value never change during execution of the program. It is often referred as literals. Character constant Character constant is a single character or a single digit or single special symbol enclosed in single quotes ('). Like ‘a’, ’b’ , ’? ’, ’2’ are all character literals. An escape sequence is a single character and stores one byte in memory. Input Stream An input stream can be defined as stream of input that is being fed into the computer (using any input device ) An >> input operator is attached to cin>> to read data from the user. Output stream Similarly an output stream is the stream of output generated by the program. << output operators is attached with output stream to print text on screen. Comments 1. Single line comments: // To write a comment on one line, type two forward slashes // and type the comment. Anything on the right side of both forward slashes would not be read by the compiler . 2. Multiline comments :/* */ To write a comment, you can start it with a forward slash / followed by an asterisk *, write the comment. To end the comment, type an asterisk * followed by a forward slash /. This type of comment can be spread on various lines. Data type: Data type defines a set of values and a set of operations that can be applied on those values which are governed by same set of rules operated by same set of operators occupies same number of bytes in memory Fundamental or basic or built in data types are those data types which are defined within the compiler . These are also known as atomic data types as they cannot be further divided into other data types. Modifiers: There are certain situations in which we need to extend the limit of the datatype provided by the compiler .In such situations C++ has provided certain type modifiers which serves the purpose of handling data in most of the situations . The four basic modifiers are : i. unsigned ii. signed iii. short iv. long A variable is a named location in memory that is used to hold a value that can be modified by the program. Type casting Type casting: Converting an expression of a given type into another type is known as typecasting To cast the data type from one type to another you specify the new type in parenthesis before the value you want to be converted . For example: to convert an integer into float ,the cast expression will be : ( float ) a int a is type cast to float Remember: Automatic conversion converts only lower data type to higher type but in type casting we can convert lower type of data to higher type of data and vice versa. Questions and answers: What is the difference between keyword and an identifier. A: Keywords are the words whose meaning is already defined to the c compiler. The keywords are also known as “reserved words” .These keywords cannot be used as variables in the program. Identifier is user defined name given to a sequence of characters . It must start with a letter or underscore and is comprised of a sequence of letters and digits What are literals in C++.How many types of literals you know in C++. A: Literals (also known as constants) are expressions with a fixed value. These are the data items whose value never change during execution of the program. It is often referred as literals. Five types of literals are there in C++ Integer literals , Floating point literals, character literal, string literals, Boolean values . What is the difference between ‘a’ and “a”? a: ‘a’ is simply a character constant that occupies one byte in memory while “a” is string literal that stores a+ \0 character in memory that means it stores 2bytes in memory. What is the size of the following :’\n’, ”hello\t”, ”Saima”, ’ \’. A: ’\n’ : 1 byte ,it is an escape sequence ”hello\t” : 7bytes (hello takes 5 bytes ,\t is an esacpe sequence takes 1byte , one for null character) ”Saima” : 6bytes( 5 bytes for saima and one for null charcter ) ’ \’ : 1 byte ,it is character constant . What is the size of the following data type in memory a. double - 8bytes b. short int -2bytes c. long int -4bytes d. long double -10bytes e. unsigned int -2bytes f. signed char -1byte g. char -1byte h. int float. 2. -2bytes -4bytes How unsigned and signed plays an important role in modifying data . A: Signed and unsigned type modifiers are used to modify the amount of storage in memory.Signed types can represent both positive and negative values, whereas unsigned types can only represent positive values (and zero). Unsigned is used to store certain values which are never negative like population count ,inventory counts etc.