Which preprocessor directive is used to insert the contents of another file into
ID: 3746440 • Letter: W
Question
Which preprocessor directive is used to insert the contents of another file into your program? Know how integer division differs from floating point division. Be able to determine what is printed to the screen with an expression like: cout << (6 + 2) * (7/ (5 - 3)) << endl; Know what the % operator does and be able to determine the result of calculations used with it. Given variable definitions and cout statements, be able to determine the output from lines of code. Which datatype only needs one byte of data to be stored?
Explanation / Answer
1. Which preprocessor directive is used to insert the contents of another file into your program?
Answer: This answer is written for C high-level programming language. In the C programming language, #include directive tells the preprocessor to insert the contents of another file into the program file. The preprocessor is a step before compilation and #include directive helps by exposing data types of variables, function prototypes etc which are defined outside of the existing program.
2. Know how integer division differs from floating point division?
Answer: This answer is written for C high-level programming language. There are mainly three data types in C 1) char 2) int and 3) float. char data type of size 8 bits. int data type can be of 16-bits, 32 bits or 64-bits. float data type is of 32-bits or 64-bits(double). Integer as the name suggests always represents whole numbers and there will not be any fractional part. In integer data type MSB bit will be considered as sign bit is for a data type which is signed (that means both positive and negative numbers). In integer division, reminder portion will be discarded. For example, the output of 5/2 will be 2. In this case, fractional part 0.5 will be discarded. Float data type indicates real numbers which can have the fractional portion also. Floating point data type follows the IEEE-754 data representation format which has a sign, exponent and the mantissa portion. For example, in the case floating point division of 5.0/2.0, the output will be 2.5.
3) Be able to determine what is printed to the screen with an expression like: cout << (6 + 2) * (7/ (5 - 3)) << endl;
Answer: In any programming language arithmetic operations follow the rule of BODMAS, I,e bracket, of, division, multiplication, addition, and subtraction. With this rule in mind, the above equation will be evaluated in following steps
a) (5-3) = 2.
b) (7/(5-3)) = (7/2) = 3 due to the fact of integer division fractional portion will be discarded.
c) (6+2) * 3 = 12 * 3 = 36.
Hence the final output of "cout << (6 + 2) * (7/ (5 - 3)) << endl;" is 36.
4) Know what the % operator does and be able to determine the result of calculations used with it.
Answer: This answer is written for C high-level programming language. % operator used in two cases a) This is used as a format specifier which is used during input and output of variable to indicate compiler what type of data is in a variable.
b) In arithmetic operations % is used as a modulus operator. This operator returns the remainder part as an answer for division operation. Example output of 5%2 is 1. The output of 11 % 4 is 3.
5) Given variable definitions and cout statements, be able to determine the output from lines of code.
Answer: This sample program is written in C++.
#include<iostream.h>
using namespace std;
int main(void)
{
int a; //define varible for integer division
float b; //define varible for floating point division
int c; //define varible for modulus operation
a = 5/2;
b = 5.0/2.0;
c = 11%4;
/* Print output of arithmetic operations on screen */
cout<<"The value of a is : "<< a <<endl;
cout<<"The value of b is : "<< b <<endl;
cout<<"The value of c is : "<< c <<endl;
return 0;
}
------------------
Output of Program is
The value of a is : 2
The value of b is : 2.5
The value of c is : 3
6) Which datatype only needs one byte of data to be stored?
Answer: This answer is written for C high-level programming language. char data type is used to store one byte of data. As in this case 8 bits are used to represent data, the range of unsigned char is 0 to 255. The range of signed char is -128 to 127
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.