0% found this document useful (0 votes)
6 views10 pages

2-Chapter 6 advanced C language

Chapter 6 of the document covers advanced C language concepts, including objective and descriptive type questions about loops, conditional statements, functions, and operators. It also discusses the importance of functions, control statements, and file handling in programming. Additionally, it provides code examples and exercises for practical understanding.

Uploaded by

arafay5607
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)
6 views10 pages

2-Chapter 6 advanced C language

Chapter 6 of the document covers advanced C language concepts, including objective and descriptive type questions about loops, conditional statements, functions, and operators. It also discusses the importance of functions, control statements, and file handling in programming. Additionally, it provides code examples and exercises for practical understanding.

Uploaded by

arafay5607
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/ 10

Chapter # 6 (Advance C Language)

Day: Classwork / Homework Date: _

Objective Type Questions


Q No 1: Choose the correct option. (Tick all that apply.)
a. How do you create a loop in C?
i. Using the "for" keyword iii. Using the "do-while" keyword
ii. Using the "while" keyword iv. All of the above
b. How do you create an if statement in C?
i. Using the "if keyword iii. Using the "else" keyword
ii. Using the "then" keyword iv. All of the above
c. How do you print output to the screen in C?
i. Using the "print" function iii. Using the "printf function
ii. Using the "echo” function iv. Ill. Using the "cout” function
d. Do while loop
i. always executes the code block at least once.
ii. cannot contain Nested Loop.
iii. the code inside its loop keeps repeating even when false.
iv. none of the above
e. Which of the below are not the types of operators being used in C language?
i. Shift Operators iii. Bitwise Operators
ii. Assignment Operators iv. Union Operators

Q No 2: Choose the correct answer. (Additional)

1. Blocks of code that perform specific tasks are called:

a. Algorithms c. Conditional block of code

b. Flowchart d. Functions

2. || represents .

a. Addition operator c. OR operator

b. AND operator d. NOT operator

3. .bin is an extension for which of the following file type?

a. Binary files c. Document files

b. Text files d. All of them


Chapter # 6 (Advance C Language)

Day: Classwork / Homework Date: _

4. Which keyword is used to take user data as input in C?

a. printf c. scanf

b. printin d. Both b and c

5. \n is a command in C language which is used for .

a. New line c. Divide something by n

b. Display the letter ‘n’ d. None of them

6. It is possible to have more than one function in C language.

a. True b. False

7. Which programming construct is best used to repeat a block of code.

a. for loop c. sequential statement

b. if statement d. Both a and b

Q No 3: Fill in the blanks:


1. C language is widely used in applications such as and .

2. main() in C language serves as a starting point of the program and calls all
other functions.

3. The output of the logical operator can be either _ True or False .

4. Consider X=3 and Y=2, the operator <= for the expression x<=y will yield the result
Fasle(0) .

5. Arguments are passed to the functions when it is called in the program.

6. Consider int x=32 and int y=14 the statement if(x>y) will yield the result
True .
Chapter # 6 (Advance C Language)

Day: Classwork / Homework Date: _

Descriptive Type Questions


Q No 4: Answer the following.
a. What is the result of the string constant "5 + 7" in C?
"5 + 7" (a string, not the numerical sum 12)

b. What is the result of the string constant "8 - 3" in C?


"8 - 3" (a string, not the numerical result 5)

c. What is the result of the string constant "6 * 4" in C?


"6 * 4" (a string, not the numerical result 24)

d. Describe different types of Operators.

Arithmetic operators:
these operators help to perform arithmetic operations. The various arithmetic
operators are given below:

Operators Description
+ Adds two operands

- Subtracts two operands

* Multiplies two operands

/ Divides numerator by denominator

% Finds remainder after division

++ Increases the value by 1

-- Decrement operator decreases the value by 1

ii. Relational operator: these test the relationship between two entities. They are given below:

Operators Description
== Checks if the value of both entities is same or not. Returns true if it is

!= Not equal to checks if both entities are same or not. If the values are not equal it
returns true
> Checks if the value of left operand is greater than the right operand

< Checks if the value of left operand is lesser than the right operand

>= Checks if the value of left operand is greater than or equal to the value

<= of right operand


Chapter # 6 (Advance C Language)

Day: Classwork / Homework Date: _

iii. Logical operators: these are used to check the conditions. They are described below

Operators Description
&& AND operator, returns true if both the operands are non-zero

|| OR operator, returns false, if any of the two operands are non-zero

! NOT operator. Used to reverse the logical state of an operand.

e. What are the advantages of Functions?


Answer:

The functions in programming provide a way of writing a piece of code once and reusing
it again and again by simply calling it wherever needed in the program, without having
the need to rewrite the code again. Using functions make programs robust and efficient.

f. Describe the function of control statements and its types.

Answer:

Control statements: these statements help to control or define the flow of the program.
With sequential statements, the programs run in the order it is written, whereas, control
statements test some conditions and then decide the flow of the program. The control
statements are:

1- Looping statements: they allow a block of code to be executed multiple times based
on some conditions. For loop, do-while loop, while loop and nested loop are
examples of looping statements.
2- Conditional statements: they test a certain condition and direct the flow of program
on basis of that. These include IF and IF-ELSE statements.

g. Why are files needed?

Answer:
The files are needed because:

1- When the program is terminated, all the data is lost. The files help preserve the data
even when the program is terminated.

2- If all the data is in the file, it can easily be accessed only by writing a few commands
in C

3- Helps to move the data from one PC to another.


Chapter # 6 (Advance C Language)

Day: Classwork / Homework Date: _

Extra Question Answers


Q No 5: Short questions and answers.

1. Spot the errors in the following codes:

a. Code 1
int main ( )

int number;

for (number = 0 ; Number < 5; number++)

printf(“welcome to C”);

return 0;

Answer:

int main ( ) // Missing '{' after main()

int number; // This line should be inside the function body

for (number = 0 ; Number < 5; number++) // 'Number' is undefined (should be 'number')

printf(“welcome to C”); // Incorrect quotation marks (should be "" not “”)

} // Extra closing brace (should be removed)

return 0; // Should be inside the function body

} // Extra closing brace (should be removed)

b. Code 2:
int main (

int x=20

int y=22

if(x<z):

printf(“variable x is less than z”)

return 0;

}
Chapter # 6 (Advance C Language)

Answer: int main ( //


Missing closing
parenthesis ')'

{ // Incorrect
placement of '{'
(should be after
'main()' properly)

int x=20 int y=22 //


Missing semicolon
';' between variable
declarations

if(x<z): // 'z' is not


declared, and ':' is not
valid in C (should be
'{')

{ // No errors
here, but must be
corrected after fixing
'if' syntax

printf(“variable x is
less than z”) //
Incorrect double
quotes “”, missing
semicolon ';'

return 0;

} // Extra closing
brace '}' (not needed
here)
Chapter # 6 (Advance C Language)

Day: Classwork / Homework Date: _

2. Write the syntax for:

a. function
int add(int a, int b) {

b. printf

printf("Hello, World!\n");

c. scanf

scanf("%d", &a);

3. Define the Escape sequence.

An escape sequence in programming refers to a series of characters used to represent


special characters or actions that are not easily typed or displayed directly in a string.

4. Mention 3 advantages of using built-in functions.

a. Time Efficiency: Built-in functions are already implemented, optimized, and


tested, so you don't need to write the code yourself. This allows you to save
time and effort, focusing on other parts of your program.

b. Improved Reliability: Since built-in functions are part of the standard library
and have been thoroughly tested, they are generally more reliable than custom
code. This reduces the likelihood of bugs and errors in your program.

c. Code Clarity and Maintainability: Built-in functions provide clear and easy-
to-understand abstractions, making your code more readable and maintainable.
They reduce the need for complex logic and make your code more concise.

Computer Science Workbook 8 (4th Edition)


Chapter # 6 (Advance C Language)

Day: Classwork / Homework Date: _

Enlist the type of operators in C.

Arithmetic Operators:

Relational Operators:

Logical Operators:

6. Define user defined function.


Answer:

A user-defined function in C is a function that is created by the programmer to


perform a specific task. Unlike built-in functions, which are provided by the C standard
library, user-defined functions are written by the programmer to address the needs of their
program.

7. Define control statement.

Answer:

A control statement in C is used to control the flow of execution in a program based on


certain conditions or loops. These statements help determine which part of the program will
be executed and how many times.

8. Define for loop.

Answer:

A for loop in C is a control statement that allows you to repeat a block of code a specific
number of times. It is commonly used when the number of iterations is known
beforehand.

Computer Science Workbook 8 (4th Edition)


Chapter # 6 (Advance C Language)

Day: Classwork / Homework Date: _

9. Draw the flowchart to illustrate conditional and Loop statements.

Computer Science Workbook 8 (4th Edition)


Chapter # 6 (Advance C Language)

Day: Classwork / Homework Date: _

10. Write a
program to print
the sum of two
numbers.
Sum = a + b
Code:
#include <stdio.h>
int main()
{ float a, b, sum;
printf("Enter the first number: ");
scanf("%f", &a);
printf("Enter the second number: ");
scanf("%f", &b);
sum = a + b;
printf("The sum of %.2f and %.2f is: %.2f\n", a, b, sum);
return 0; }

11. Write a
program to
calculate the
area of
rectangle.
Area = I * b
#include <stdio.h>
int main()
{ float length, breadth, area;

printf("Enter the length of the rectangle: ");


scanf("%f", &length);
printf("Enter the breadth of the rectangle: ");
scanf("%f", &breadth); area = length * breadth;

printf("The area of the rectangle is: %.2f\n", area);

return 0;

Computer Science Workbook 8 (4th Edition)

You might also like