0% found this document useful (0 votes)
17 views6 pages

CT1 Set 4

The document contains a series of questions and answers related to the C programming language, covering topics such as keywords, data types, algorithms, operators, control statements, arrays, and memory allocation. It includes multiple-choice questions, syntax definitions, and programming examples. Additionally, it outlines rules for forming identifiers and provides explanations for various programming concepts.

Uploaded by

nimishparmar06
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)
17 views6 pages

CT1 Set 4

The document contains a series of questions and answers related to the C programming language, covering topics such as keywords, data types, algorithms, operators, control statements, arrays, and memory allocation. It includes multiple-choice questions, syntax definitions, and programming examples. Additionally, it outlines rules for forming identifiers and provides explanations for various programming concepts.

Uploaded by

nimishparmar06
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/ 6

SE Question C P B Ma PIC

O O L rks ODE
T4
Sl.N
o

1 Standard ANSI C recognizes ____________ number of 1 1 1 1


keywords

a) 30
b) 32
c) 36
d) 42
2 The format identifier ‘%Lf’ is also used for _____ data 1 2 1 1
type.

a) Unsigned Int
b) Double
c) Unsigned Long
d) Long Double
3 Consider the below Algorithm and find the Step Number 1 2 1 1
in which there is an error? Step1:
Start

Step 2: Declare variables num1, num 2 and sum.

Step 3: Read values num1and num2.

Step 4: Add num1 and num2 and assign the result to


sum. Sum=num1+num 2

Step 5: Read sum

Step 6: Stop.

a) Step 2
b) Step 3
c) Step 5
d) Step 4
Find the output for the following program 1 2 1 1

4 #include <stdio.h>

void main() {

inti=-1;

printf("i = %d\n", i--);

a) 1
b) -1
c) 0

d) 2

Identify the operator type that is used to compare two 1 2 3 1


values
5
a) Unary
b) Relational
c) Assignment
d) Equal
6 The continue statement cannot be used with 2 2 3 1

a) for
b) while
c) do while
d) switch
Which of the following is an invalid if-else statement? 2 2 3 1

7 a) if (if (a == 1)){}
b) if (a){}
c) if ((char) a){}
d) if (func1 (a)){}
8 Do-while loop terminates when conditional expression 2 2 3 1
returns?

a) One
b) Zero
c) Non - zero
d) None of the above

9. What will be the output of the following C code? 2 2 3 1

#include <stdio.h>

void main()

int k = 0;

for (k)

printf("Hello");

a) Compile time error

b) hello

c) Nothing

d) Varies

10 What is the return type of malloc() or calloc() 2 2 2 1

a) void *
b) Pointer of allocated memory type
c) void **
d) int *
II List out the rules to be followed in forming in identifier?
 Combination of alphabets, digits (or) underscore
 First character should be a Alphabet
 No special characters other than underscore can be used
 No comma / spaces allowed within variable name
 A variable name cannot be a keyword
 Variable names are case sensitive

12 Define ternary operator with suitable example


Syntax
condition ? value_if_true : value_if_false

The statement evaluates to value_if_true if condition is met, and value_if_false


otherwise.

13 Write the syntax for all the three iterative control statements

Iterative Statement in C

In computer programming, sometimes programmer have to perform same task again


and again on the same data with a few changes. In this situation programmer can either
write same code again and again which consumes lots of time and space as well over
can use loop to iterate same code to save time and space.

Following are the loops used in C/C++ programming


1. for loop
2. while loop
3. do-while loop

14 Write the features of arrays


 An array is always stored in consecutive memory location.
 It can store multiple value of similar type, which can be referred with single name.
 The pointer points to the first location of memory block, which is allocated to the array
name.
 An array can either be an integer, character, or float data type that can be initialised
only during the declaration.
 The particular element of an array can be modified separately without changing the
other elements.
 All elements of an array can be distinguishing with the help of index number.

Part C 2*10-20 Mac

Answer all question


15.What is a tokens explain each and every elements c tokens

(OR)

15 b. Briefly about the unconditional looping statements with suitable example


UNCONDITIONAL LOOP
For Loop – Counted Loops
Uncounted Loop – Infinite loop
Uncounted Loop –infinite loop controlled by control statements.
WHILE STATEMENTS
The while statement is used to carry out looping operations, in which a group of
statement is executed repeatedly, until some condition has been satisfied.

The general form of statement is

while (test expression)

statement to be executed;

or

while (test expression)

{ statements to be executed }

The statement will be executed repeatedly as long as the test expression is true. The
statement can be simple or compound, though it is usually a compound statement.

It must include some features that eventually alters the value of the expression, thus
providing stopping condition for the loop.
16a. Illustrate two-dimensional arrays with example.
An array is a collection of fixed number values of a single type. Hence, an integer array
can only hold elements whose data type is also an integer.

A two-dimensional array in C can be thought of as a matrix with rows and columns. The
general syntax used to declare a two-dimensional array is:

svg viewer

A two-dimensional array is an array of several one-dimensional arrays. Following is an


array with five rows, each row has three columns:

int my_array[5][3];
The code above declares a one-dimensional array that has five elements. Each of these
five elements is themselves, an array of three integers. The following diagram shows a
simple way to visualize this:
An array of arrays is known as 2D array. The two dimensional (2D) array in C programming is
also known as matrix. A matrix can be represented as a table of rows and columns.
The syntax to declare the 2D array is
data_type array_name[rows][columns];
Initialization of 2D Array in C
In the 1D array, we don't need to specify the size of the array if the declaration and initialization
are being done simultaneously.
However, this will not work with 2D arrays. We will have to define at least the second
dimension of the array. The two-dimensional array can be declared and defined in the following
way.
int arr[4][3]={{1,2,3},{2,3,4},{3,4,5},{4,5,6}};
(OR)
16b. Write a C program to count the number of digits in given number
#include <stdio.h>
int main() {
long long n;
int count = 0;
printf("Enter an integer: ");
scanf("%lld", &n);
// iterate at least once, then until n becomes 0
// remove last digit from n in each iteration
// increase count by 1 in each iteration
do {
n /= 10;
++count;
} while (n != 0);
printf("Number of digits: %d", count);
}

You might also like