TCS PROGRAM LOGIC
1. Find the error(s) in the following code, if any.
#include
int main()
{
printf(The Sun sets in the West)
return 0;
}
- In the print statement, the phrase The Sun sets in the West should be in double quotes.
- At the end of the print statement, there should be a semi colon.
- Both A and B
- No error
Answer : 3
Explanation : the phrase The Sun sets in the West, should be inside double quotes, and the statement should end with a semicolon.
2. Which is correct with respect to the size of the data types?
- int > char > float
- char > int > float
- char < int < double
- char < int < float
Answer
Answer : 3 Explanation : Char has less bytes than int and int has less bytes than double in any system.
- size(type)
- sizeof(type)
- variableSize(type)
Answer
Answer : 2Explanation :To get the exact size of a type or a variable on a particular platform, you can use the sizeof operator. The expressions sizeof(type) yields the storage size of the object or type in bytes.
Program
#include
int main() {
printf("Storage size for float is: %d \n",sizeof(float));
return 0;
}
4.Which of the following options has incorrect variable naming?
- int num1;
- int _firstAlpha;
- int 1st_number;
- int aero_pilot;
- Answer
Answer
Answer : 3int i = 4;5.The above line of code is an example of:
- Variable Definition
- Variable Declara tion
Answer
Answer : 1Explanation : int i = 4 is an example of Variable Definition.
6.Predict the output:
#include
int main()
{
float c = 10.0;
printf ("Temperature in Fahrenheit is %.2f", (9/5)*c + 32);
return 0;
}
- Temperature in Fahrenheit is 50.00
- Temperature in Fahrenheit is 42.00
- Temperature in Fahrenheit is 0.00
- Compile Time Error
Answer
Answer : 2
Explanation : Since 9 and 5 are integers, integer arithmetic happens in subexpression (9/5) and we get 1 as its value. To fix the above program, we can use 9.0 instead of 9 or 5.0 instead of 5 so that floating point arithmetic happens.
7.What is the size of an int data type?
- 4 bytes
- 8 bytes
- Depends on the system/compiler
- Cannot be determined
Answer
Answer : 1
Explanation : in data type having 4 bytes
8.What is short int in C programming?
- Basic data type of C
- short is the qualifier and int is the basic data type
- qualifierr
- All of the above
Answer
Answer : 2
Explanation :
9.Which of the following is not a data type?
- Symbolic Data
- Alphanumeric Data
- Numeric Data
- Alphabetic Data
Answer
Answer : 4
Explanation : Numeric Data consists of only numbers. Alphabetic Data consists of only letters and a blank character and alphanumeric data consists of symbols. So, a symbolic data type not exists.
10.What are the entities whose values can be changed called?
- Constants
- Variables
- Modules
- Tokens
Answer
Answer : 2
Explanation :

No comments:
Post a Comment
Thank you