BSc Sem 1 Computer Paper 2017 Answers of 1 B, C, D
Question 1 (B) answer in brief (Any one) 2 marks
1. Explain history of C++.
Background History:
· C++ Development started in 1979.
· During the creation of Ph.D. thesis, Bjarne Stroustrup worked with language called Simula.
· Simula is basically useful for the simulation work.
· Simula was first language to support object-oriented programming paradigm
· Bjarne Stroustrup identified that this OOP features can be included in the software development.
· After that Bjarne Stroustrup started working on the C language and added more extra OOP features to the classic C.
· He added features in such a manner that the basic of C remains unaffected.
· C++ includes some add-on features such as classes, basic inheritance, in-lining, default function arguments, and strong type checking
Basic History of C++
· During 1970 Dennis Ritchie created C Programming language.
· In the early 1980’s, also at Bell Laboratories, another programming language was created which was based upon the C language.
· C++ is also called as C with classes
· Stroustrup states that the purpose of C++ is to make writing good programs easier and more pleasant for the individual programmer.
· C++ programming language is extension to C Language.
· In C we have already used increment operator (++). Therefore we called C++ as “Incremented C” means Extension to C.
2. Explain keyword.
Keywords in C Programming Language:
· Keywords are those words whose meaning is already defined by Compiler
· Cannot be used as Variable Name
· There are 32 Keywords in C for eg. if, break, int, while, return etc.
· C Keywords are also called as reserved words.
Question 1 (C) answer in detail (Any one) 3 marks
1. Write rules for variable name.
Rules For Constructing Variable Name
1. Characters Allowed :
· Underscore(_)
· Capital Letters ( A – Z )
· Small Letters ( a – z )
· Digits ( 0 – 9 )
2. Blanks & Commas are not allowed
3. No Special Symbols other than underscore(_) are allowed
4. First Character should be alphabet or Underscore
5. Variable name Should not be Reserved Word
2. Explain type casting.
Type casting is a way to convert a variable from one data type to another data type. For example, if you want to store a 'long' value into a simple integer then you can type cast 'long' to 'int'. You can convert the values from one type to another explicitly using the cast operator as follows
(type_name) expression
Consider the following example where the cast operator causes the division of one integer variable by another to be performed as a floating-point operation
#include <stdio.h>
main() {
int sum = 17, count = 5;
double mean;
mean = (double) sum / count;
printf("Value of mean : %f\n", mean );
}
if the operands still have different types, then they are converted to the type that appears highest in the following hierarchy −
Question 1 (D) write a note on (Any one) 5 marks
1. Explain data types in c++.
In C programming, variables or memory locations should be declared before it can be used. Similarly, a function also needs to be declared before use.
Data types simply refer to the type and size of data associated with variables and functions.
Data types in C
1. Fundamental Data Types
· Integer types
· Floating type
· Character type
2. Derived Data Types
· Arrays
· Pointers
· Structures
· Enumeration
INTEGER DATA TYPE:
· Integer data type allows a variable to store numeric values.
· “int” keyword is used to refer integer data type.
· The storage size of int data type is 2 or 4 or 8 byte.
· It varies depend upon the processor in the CPU that we use. If we are using 16 bit processor, 2 byte (16 bit) of memory will be allocated for int data type.
· Like wise, 4 byte (32 bit) of memory for 32 bit processor and 8 byte (64 bit) of memory for 64 bit processor is allocated for int datatype.
· int (2 byte) can store values from -32,768 to +32,767
· int (4 byte) can store values from -2,147,483,648 to +2,147,483,647.
· If you want to use the integer value that crosses the above limit, you can go for “long int” and “long long int” for which the limits are very high.
CHARACTER DATA TYPE:
· Character data type allows a variable to store only one character.
· Storage size of character data type is 1. We can store only one character using character data type.
· “char” keyword is used to refer character data type.
· For example, ‘A’ can be stored using char datatype. You can’t store more than one character using char data type.
FLOATING POINT DATA TYPE:
Floating point data type consists of 2 types. They are,
1. FLOAT:
· Float data type allows a variable to store decimal values.
· Storage size of float data type is 4. This also varies depend upon the processor in the CPU as “int” data type.
· We can use up-to 6 digits after decimal using float data type.
· For example, 10.456789 can be stored in a variable using float data type.
2. DOUBLE:
· Double data type is also same as float data type which allows up-to 10 digits after decimal.
· The range for double datatype is from 1E–37 to 1E+37.
2. Explain operators in c.
An operator is a symbol which operates on a value or a variable. For example: + is an operator to perform addition.
C programming has wide range of operators to perform various operations. For better understanding of operators, these operators can be classified as:
C Arithmetic Operators
An arithmetic operator performs mathematical operations such as addition, subtraction and multiplication on numerical values (constants and variables).
Operator
|
Meaning of Operator
|
+
|
addition or unary plus
|
-
|
subtraction or unary minus
|
*
|
multiplication
|
/
|
division
|
%
|
remainder after division( modulo division)
|
Increment and decrement operators
C programming has two operators increment ++ and decrement -- to change the value of an operand (constant or variable) by 1.
Increment ++ increases the value by 1 whereas decrement -- decreases the value by 1. These two operators are unary operators, meaning they only operate on a single operand.
C Assignment Operators
An assignment operator is used for assigning a value to a variable. The most common assignment operator is =
Operator
|
Example
|
Same as
|
=
|
a = b
|
a = b
|
+=
|
a += b
|
a = a+b
|
-=
|
a -= b
|
a = a-b
|
*=
|
a *= b
|
a = a*b
|
/=
|
a /= b
|
a = a/b
|
%=
|
a %= b
|
a = a%b
|
C Relational Operators
A relational operator checks the relationship between two operands. If the relation is true, it returns 1; if the relation is false, it returns value 0.
Relational operators are used in decision making and loops.
Operator
|
Meaning of Operator
|
Example
|
==
|
Equal to
|
5 == 3 returns 0
|
>
|
Greater than
|
5 > 3 returns 1
|
<
|
Less than
|
5 < 3 returns 0
|
!=
|
Not equal to
|
5 != 3 returns 1
|
>=
|
Greater than or equal to
|
5 >= 3 returns 1
|
<=
|
Less than or equal to
|
5 <= 3 return 0
|
C Logical Operators
An expression containing logical operator returns either 0 or 1 depending upon whether expression results true or false. Logical operators are commonly used in decision making in C programming.
Operator
|
Meaning of Operator
|
Example
|
&&
|
Logial AND. True only if all operands are true
|
If c = 5 and d = 2 then, expression
((c == 5) && (d > 5)) equals to 0. |
||
|
Logical OR. True only if either one operand is true
|
If c = 5 and d = 2 then, expression
((c == 5) || (d > 5)) equals to 1. |
!
|
Logical NOT. True only if the operand is 0
|
If c = 5 then, expression
! (c == 5) equals to 0. |
Bitwise Operators
During computation, mathematical operations like: addition, subtraction, addition and division are converted to bit-level which makes processing faster and saves power.
Bitwise operators are used in C programming to perform bit-level operations.
Operators
|
Meaning of operators
|
&
|
Bitwise AND
|
|
|
Bitwise OR
|
^
|
Bitwise exclusive OR
|
~
|
Bitwise complement
|
<<
|
Shift left
|
>>
|
Shift right
|
Comma Operator
Comma operators are used to link related expressions together. For example:
int a, c = 5, d;
The sizeof operator
The
sizeof
is an unary operator which returns the size of data (constant, variables, array, structure etc).
Comments
Post a Comment