0% found this document useful (0 votes)
123 views

Week-2-July-2023 Solution

This document provides solutions to 10 multiple choice questions about basic C programming concepts. The key points covered are: - Valid variable names in C - Functions and their properties - Execution order of C programs - Types of errors - Data types and storage sizes - Basic operations like variable declaration, printing, and arithmetic - Operator precedence (BODMAS)

Uploaded by

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

Week-2-July-2023 Solution

This document provides solutions to 10 multiple choice questions about basic C programming concepts. The key points covered are: - Valid variable names in C - Functions and their properties - Execution order of C programs - Types of errors - Data types and storage sizes - Basic operations like variable declaration, printing, and arithmetic - Operator precedence (BODMAS)

Uploaded by

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

Problem Solving through Programming in C

Week 2 Assignment Solution

1. Which of the following is not a C variable?


a) Count123
b) Count_123
c) Count@123
d) X_123_Count

Solution: (c) Only alphanumeric characters and few special characters like ‘_’ are allowed in
variable name is C. The special character @ is not allowed.

2. A function
a) is a block of statements to perform some specific task
b) is a fundamental modular unit to perform some task
c) has a name and can be used multiple times
d) All the above options are true

Solution: (d) All the above options are true

3. The execution of any C program is

a) Sequential
b) Parallel
c) Multi-threading
d) None of these

Solution: (a) The execution of the C program is sequential.


4. Syntax error occurs when
a) The rules of grammar of the programming language is violated
b) The statements in the program have no meaning
c) The program gives wrong or undesired output
d) Some illegal operation (e.g. divide by zero) is performed
Solution: (a) The rules of grammar of the programming language is violated
5. If integer needs two bytes of storage, then the minimum value of a signed integer in C
would be

a) -65535
b) 0
𝑐) -32,767
d) -32,768

Solution: (d) The first bit is used to indicate whether it is signed or unsigned integer. So it
will be −215 i.e. -32,768
Problem Solving through Programming in C

Week 2 Assignment Solution

6. What will be the output of the program given below?


#include <stdio.h>
int main()
{
a=9;
printf("%d", a);
return 0;
}

a) 9
b) 0
c) 1001
d) Compilation Error

Solution: (d) Compilation Error

variable ‘a’ is not declared therefore a compilation error.

7. What is the output?


#include<stdio.h>
#define fun(x) (x*x)
int main()
{
float i;
i = 64.0/fun(2);
printf("%.2f", i);
return 0;
}

a) 8.00
b) 4.00
c) 0.00
d) 16.00
Solution: (d) The pre-processing replaces fun(2) with (2*2). Thus fun(2)=4, so,
i=64.0/4=16.00

8. The following C program swaps the value of two numbers without using any third
variable. What will be the correct option to fill up the blank?

#include <stdio.h>
Problem Solving through Programming in C

Week 2 Assignment Solution

int main()
{
int a=2, b=3;
printf("The values before swapping a = %d, b=%d", a, b);

____________________________________

printf("The values after swapping a = %d, b=%d", a, b);


return 0;
}

a) a=a-b; b=a-b; a=a+b;


b) a=a%b; b=a+b; a=a/b;
c) a=a+b; b=a-b; a=a-b;
d) None of the above
Solution: (c) a=a+b; b=a-b; a=a-b;

9. What will be the output?


#include <stdio.h>
int main() {
int x = 1, y = 3;
int t = x;
x = y;
y = t;
printf("%d %d", x, y);
return 0;
}

a) 1 3
b) 3 1
c) 1 1
d) 3 3

Solution: (b) 3 1
Here the program is swapping the values of the variables x and y. A temporary variable t is
used for the swapping purpose.
10. When executed the following code will print _______.
#include <stdio.h>
int main() {
int sum = 3 + 6 / 2 + 6 * 2;
printf("%d", sum);
return 0;
}

Solution: 18 (short answer type)


Apply the BODMAS rule to evaluate the expression.

You might also like