Pageviews

Friday 6 September 2019

+1]5 . Data Types And Operators - Previous Questions from chapter wise



               PLUS ONE 
COMPUTER APPLICATION / COMPUTER SCIENCE

            First Year Computer Application(Commerce) Previous Questions Chapter wise ..


                                         Chapter  5 (6 for CS) Data Types And Operators




1. Given that x= 5  y=5. What will be the value of the expression x > y|| y > x? 

     Ans. False

2.  While writing a C++ program, a student forget to put semicolon at the end of a   declaration                  statement.What type of error can he expect during compilation ? 

     Ans. Syntax Error

3.   The memory size of float data type in C++ is ...............  bytes.


    a)2

     b)4 

     c)8 

      d)10 

   Ans. b

4.  Explain different types of  logical operators on C++

   and (&&):( Result will be true  only if both the combined expressions have true value)      

  or(||):Result will be true  only if any of  the combined expressions have true value )     

 not(!): To get the negation of the give expression

 d). input/out put operators: input(get from or extract operator), output (put to or  insertion operator) 

e). Assignment operator: = (to assign a value to a variable). 

5.  What is the difference between “=” and “= =” operators?

           When we have to store a value in a memory location, assignment operator (=) is used. This is a binary operator and hence two operands are required. The first operand should be a variable where the value of the second operand is to be stored.

         The = symbol assigns a value to a variable, whereas == symbol compares two values and gives True or False as the result.

6.   What is the difference between  x= 5  and x ==5 in C++

          x=5 means the value 5 is assigned or stored the variable X but X==5 means both values are compares and it gives true or false as the result. 

7. Identify the name of following operators in C++. 
      && , || , !

  Ans. && : Logical And

           ||  : Logical Or

            ! : Logical Not

8.  .Write the declaration in C++ for a variable that can be used to store height of  a   student.                    Justify, why you  have selected this data type in the declaration. 

  Ans. float Height ;

9.  Which of the following is not a character constant in C++? 
      a) ‘a’

      b) a

      c) ‘8’

       d)’\a’  

    Ans. b

10. . Memory requirement of void data type in C++ is .......... byte(s

     Ans. 0 byte

11. .Let X and Y are two variables of int data type, then correct the following  input                               statement.  

  cin<< X >> Y;

   Ans. cin>>X>>Y;

12. Write the output of the following C++ expressions. Let a=7,b=2.

     a) a+b *3/ ++b;    

     b) a<=7&&b>1;

   Ans. a) 7+2*3/++2 = 7+2*3/3 =7+2*1 =7+2=9

            b) 7<=7&&2>1 ----->True statement 

13.  Write value returned by the C++ expressions

      a). 60 % 25;

      b).  22 / 7; 


     Ans. a. 10

              b. 3


14.  How do the type modifiers affect the size and range of int and char data types?

          By using different number of bytes to store values, C++ offers three types of integers : short, int, and long that can represent up to three different integer sizes. Each comes in both signed and unsigned versions.In integer 4 bytes are used,ranges from 2147483648 to +2147483647.

     

The char type can also be signed or unsigned. Unlike int, char is neither signed nor unsigned by default. The choice is left to the C++ implementation in order to allow the implementer to best fit the type to the hardware properties.

However, these distinctions are particularly important if you are using char as a numeric type. The unsigned char represents the range 0 to 256 and signed char represents the range -128 to 127.In char 1 byte is used.

15 . Explain the difference between float g=9.8 ; and const float g=9.8?

             ref 6th chapter QS 12

16. What is implicit type conversion?Why it is called type promotion ?

             Implicit Type Conversion also known as 'automatic type conversion'. Done by the compiler on its own, without any external trigger from the user. Generally takes place when in an expression more than one data type is present. In such condition type conversion (type promotion) takes place to avoid lose of data.

17.  Distinguish between float and double data types in C++.

            Float : They are numbers with fractional part. It uses four bytes of memory. It  can be                                      represented either by scientific notation or mantissa exponential  method. 

          Double: It is used for handling large floating point numbers. It uses 8 bytes of memory.

18. . What is a variable ?Differentiate between memory address and content of the variable.

           Name given to a memory location is known as variable. It is use to store and retrieve data. It have three part: a) variable name  b). Memory address(starting address of the allocated memory)       c). Content .

       The RAM of a computer consists of collection of cells each of which can store one byte of data. Every cell (or byte) in RAM will be assigned a unique address to refer it. All the variables are connected to one or more memory locations in RAM. The base address of a variable is the starting address of the allocated memory space.

    The value stored in the location is called content of the variable. This is also called the R-value of the variable. Type and size of the content depends on the data type of the variable. Here the variable name is Num and it consumes 4 bytes of memory at memory addresses 1001, 1002, 1003 and 1004. The content of this variable is 18. That is L-value of Num is 1001 and R-value is 18.


           Image result for memory allocation of a variable images    
19.  Briefly explain any two expressions in C++. 

         expressions are composed of operators and operands. It is evaluated to get a         value(returning of value) On the basis of operators expressions can be divided into,

 a). Arithmetic expression: Expression in which arithmetic operators are used ( may be integer  or             floating point expression)

 b). Relational expression : Expression in which relational operators are used 

20.  Predict the output of the following operations. x = -5 and y = 3 initially.           

a). –x 

b). x/y  

c). x % y 

d). –x + -y 

Ans.a.  -(-5) = 5

         b.  -5/3 =-1

           c. -5%3 = -2

            d. -(-5)+-3 =2

21. . Consider the following statement.  int length;          
Then what is the difference between (a) and (b)?  a). length = 50; b). length = = 50; 

         refer Qs no.s 5 and 6

22.  Write sample statements in C++ for the cascading of input and output operators

            Multiple use of Input / Output operators in a single statement is called cascading of I/O Operator. Here the values are assigned to the variables from left to right.

 Eg. cout << x <<y <<z;

         cin >> x >> y;

23.  Explain the operations involved in the following C++ expressions and write the output.

 a) 5/2+3

 b) (10%3)/2.0

   Ans. a. 5

           b. 0.5

24. Write four different C++ statements to add 1 to the value stored in the variable     
   Num.

25.  What is the output of the following C++ statements.
   X= -7    Y = 3
   a) add –x with –y
   b) x  modulus  y

  Ans. a. -(-7)+3 =10

          b. -7%3 = -1

26. . What are data types ?Explain the fundamental data types in C++.

            Data types are the means to identify the nature of the data and the set of operations that can be performed on the data.

    There are three types of data types C++,

a). Fundamental data type (built in Data types):

 They are defined in the C++ compiler. They can not be further broken down. There are 5 types of Fundamental data types,

1). Char: They are symbols covered by the character set of C++ language. It uses only one byte                       of memory (storing in memory with its ASCII value). 

2). Int  : Whole numbers without fractional part. It can be positive or negative, or zero. It uses                       Four bytes of memory based on GCC compiler.

 3). Float : They are numbers with fractional part. It uses four bytes of memory. It  can be                            represented either by scientific notation or mantissa exponential  method.

 4). Double: It is used for handling large floating point numbers. It uses 8 bytes of memory.

 5). Void : uses zero bytes of memory.

27.  Classify the identifiers given below as valid and invalid .Give reason for invalidity.

sum

if

_Num 1

Switch

stud Age

   Ans. Valid: sum,_Num1

          Invalid : if ,Switch,stud Age

       if and Switch are keywords. stud Age is invalid identifier because white space is prohibited.

28.If a=5, b=7 and c=3.  Predict the output of the following expresssions.

a) a<c

b) b%a

 c) (a<c) && (a<b)

 d) a/c

  Ans. a. False

            b. 7%5 = 2

             c. False

              d. 5/3 =1

29.  Predict the value of 'b' in the following C++ code after execution of each code snippet

   a) and  b) Justify your answer.

 a) a = 5; b = a++;

 b) a = 5; b = ++a;

Ans. a. b=5

          b. b=6

30.   List the three numeric data types in C++ with an example for each

31.  If a = 5,   b = 4,   c = 3,  d = 4 then what is the result in x after following operation?

       X=a + b – c * d;

        Ans. X =5+4-3*4 = 5+4-12 = -3

32.  Is there any difference between (a) and (b) by considering the following statement?   char             Gender;        a). Gender  = ‘M’;        b). Gender = “M”;

          In Gender='M' means  Characters are the symbols covered by the character set of the C++ language. All letters, digits, special symbols, punctuations, etc. come under this category. When these characters are used as data they are considered as char type data in C++. We can say that the keyword char represents character literals of C++. Each char type data is allowed one byte of memory.

        Gender="M" is wrong statement because single character representation using single quote.

33.  Write a short note on arithmetic And logical operators in C++.

          Arithmetic operators are defined to perform basic arithmetic operations such as addition, subtraction, multiplication and division. The symbols used for this are +, -, * and / respectively. C++ also provides a special operator % (modulus operator) for getting remainder during division. All these operators are binary operators. Note that + and - are used as unary operators too. The operands required for these operations are numeric data. The result of these operations will also be numeric.

         Using relational operators, we can compare values. Examples are 3<5, num!=10, etc. These comparison operations are called relational expressions in C++. In some cases, two or more comparisons may need to be combined. In Mathematics we may use expressions like a>b>c. But in C++, it is not possible. We have to separate this into two, as a>b and b>c and these are to be combined using the logical operator &&, i.e. (a>b)&&(b>c). The result of such logical combinations will also be either True or False (i.e. 1 or 0). The logical operators are && (logical AND), || (logical OR) and ! (logical NOT).

34.  Write the equivalent arithmetic operations for the given C++ short hands.

 i) x% =20;    il) a+=2;   Iii)p / = 5;

 b) What is the difference between a = 20 and a = = 20?

     Ans. X=X%20
    
            b. a=a+2

             c. p=p/5


          a=20 means  the constant 20 is assigned to the variable a. a==20 means compares two values and it gives may true or false as the result.

35.  Classify the following identifiers valid or invalid. If invalid give reason.

 a). Length_1

 b). _Length1

c). Length 1

d). 1Length 

Ans. Valid: Length_1 ,_Length1

          Invalid : Length 1 ,1Length. Because identifiers are not using digit in first and Between words white spaces are not  alloweded.