0% found this document useful (0 votes)
4 views5 pages

Basic Building Block Assignment1

The document consists of a series of questions and code snippets related to C programming, covering topics such as variable declarations, output predictions, and error handling. It includes multiple-choice questions that test knowledge on valid variable names, keyword usage, and the behavior of specific code examples. Additionally, it provides programming exercises for calculating areas and salaries, as well as type casting and output formatting.

Uploaded by

mk6510459
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views5 pages

Basic Building Block Assignment1

The document consists of a series of questions and code snippets related to C programming, covering topics such as variable declarations, output predictions, and error handling. It includes multiple-choice questions that test knowledge on valid variable names, keyword usage, and the behavior of specific code examples. Additionally, it provides programming exercises for calculating areas and salaries, as well as type casting and output formatting.

Uploaded by

mk6510459
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Unit-II

Assignment I

1. Which of the following is not a valid variable name declaration?


a)int _a3; b)int a_3;
c)int 3_a; d)int _3a;

2. Variable names beginning with an underscore is not encouraged. Why?


a) It is not standardized
b) To avoid conflicts since assemblers and loaders use such names
c) To avoid conflicts since library routines use such names
d) To avoid conflicts with the environment variables of an operating system

3. All keywords in C are in


a) Lower Case letters b) Upper Case letters
c) CamelCase letters d) None

4. What is the output of this C code?


#include <stdio.h>
#define a 10
void main( )
{
constint a = 5;
printf("a = %d\n", a);}
a) a = 5 b) a = 10
c) Compilation error d) Runtime error

5. The format identifier ‘%i’ is also used for _____ data type?
a) Char b) Int
c) Float d) Double

6. What is the output of this C code?


#include <stdio.h>
void main( )
{
intvar = 010;
printf("%d", var);
}
a) 2 b) 8
c) 9 d) 10

7. What is the output of this C code?


#include <stdio.h>
void main( )
{
printf("C programming %s", "Class by\n%sTppDepartment", "WOW");
}
a) C programming Class byWOWTppDepartment
b) C programming Class by\n%sTppDepartment
c) C programming Class by %s TppDepartment
d) Compilation error

8. What is the output of this C code?


#include <stdio.h>
int main( )
{
enum {ORANGE = 5, MANGO, BANANA = 4, PEACH};
printf("PEACH = %d\n", PEACH);
}
a) PEACH = 3 b) PEACH = 4
c) PEACH = 5 d) PEACH = 6

9.In which stage the following code


#include<stdio.h>
gets replaced by the contents of the file stdio.h
a) During editing
b) During linking
c) During execution
d) During preprocessing
Answer: d

10. What is the output of this C code?


#include <stdio.h>
int main( )
{
printf("Hello World! %d \n", x);
return 0;}
a) Hello World! x;
b) Hello World! followed by a junk value
c) Compile time error
d) Hello World!

11. What is the output of this C code?


#include <stdio.h>
int main( )
{
int y = 10000;
int y = 34;
printf("Hello World! %d\n", y);
return 0;
}
a) Compile time error b) Hello World! 34
c) Hello World! 1000 d) Hello World! followed by a junk value

12. What will happen if the below program is executed?


#include <stdio.h>
int main( )
{ int main = 3;
printf("%d", main);
return 0;
}
a) It will cause a compile-time error
b) It will cause a run-time error
c) It will run without any error and prints 3
d) It will experience infinite looping

13. What is the problem in following variable declaration?


float 3Bedroom-Hall-Kitchen?;
a) The variable name begins with an integer
b) The special character ‘-’
c) The special character ‘?’
d) All of the mentioned

14. Comment on the output of this C code?


#include <stdio.h>
int main( )
{
intThisIsVariableName = 12;
intThisIsVariablename = 14;
printf("%d", ThisIsVariablename);
return 0;
}
a) The program will print 12.
b) The program will print 14.
c) The program will have a runtime error.
d) The program will cause a compile-time error due to redeclaration

15. Which of the following cannot be a variable name in C?


a) volatile b) true
c) friend d) export

16. C program to calculate area of Right angle triangle


17. Write a program to read the values of x, y and z and print the results of the following
expressions in one line.
(x+y+z) / (x-y-z)
(x+y+z) / 3
(x+y) * (x-y) * (y-z)

Output:
Enter the values of x,y and z : 1.1 2.5 5.5
1
Value of a = -1.000000
2
Value of b = 2010.000000
3
Value of c = 27939.000000
4

18 . C Program to calculate gross salary of a person.

Output :
1 Enter basic Salary : 1000
2 Gross Salart : 1220

19. Write a program to type cast int to float.

Output:
Result with type casting: 3.333333

20. What will be the output of following program ?


#include<stdio.h>
int main( )
{
inti=2,j=3,k,l;
floata,b;
k = i/j * j;
l = j/i * j;
a = i/j * j;
b = j/i * i;
printf("%d %d%f%f\n",k,l,a,b);
return 0;}
a) 3, 0, 0, 0 b) 0, 3, 0.000000, 2.000000
c) 0,0,0,0 d) Error

21. What will be the output of following program?


#include<stdio.h>
int main( )
{
float a=5,b=2;
intc,d;
c =a%d;
d =a/2;
printf("%d\n",d);
return 0; }
a) 3 b) 2
c) Error d) None of above

22. What will be the output of the program?


#include<stdio.h>
int main( )
{ printf("nn /n/n nn/n");
return 0; }
a) Nothing b) nn /n/n nn/n
c) nn /n/n d) Error

23. What will be output of following c code?


void main( )
{
char i=250;
printf(“%d”,i);
}

You might also like