Total Pageviews

TCS PROGRAM LOGIC Level 1

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;
}

  1. In the print statement, the phrase The Sun sets in the West should be in double quotes.
  2. At the end of the print statement, there should be a semi colon.
  3. Both A and B
  4. 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?
  1. int > char > float
  2. char > int > float
  3. char < int < double
  4. char < int < float


Answer
Answer
: 3 Explanation : Char has less bytes than int and int has less bytes than double in any system.

3.To get the exact size of a type or a variable on a particular platform, which of the following will you use?
  1. size(type)
  2. sizeof(type)
  3. variableSize(type)
Answer Answer : 2
Explanation :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?
  1. int num1;
  2. int _firstAlpha;
  3. int 1st_number;
  4. int aero_pilot;
  5. Answer
Answer Answer : 3 Explanation :This is an incorrect naming of the variable, because as per the second rule, the first letter of a variable can only be an alphabet or an underscore.


int i = 4;
5.The above line of code is an example of:
  1. Variable Definition
  2. Variable Declara tion

Answer Answer : 1
Explanation : 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; 
} 

  1. Temperature in Fahrenheit is 50.00
  2. Temperature in Fahrenheit is 42.00
  3. Temperature in Fahrenheit is 0.00
  4. 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?
  1. 4 bytes
  2. 8 bytes
  3. Depends on the system/compiler
  4. Cannot be determined

Answer
Answer : 1
Explanation : in data type having 4 bytes

8.What is short int in C programming?
  1. Basic data type of C
  2. short is the qualifier and int is the basic data type
  3. qualifierr
  4. All of the above
Answer
Answer : 2
Explanation :

9.Which of the following is not a data type?
  1. Symbolic Data
  2. Alphanumeric Data
  3. Numeric Data
  4. 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?
  1. Constants
  2. Variables
  3. Modules
  4. Tokens

Answer
Answer : 2
Explanation :

No comments:

Post a Comment

Thank you