C Programming and Data Structures: Unit I: C Programming Fundamentals : Two Marks Questions with Answers
Two Marks Questions with Answers
Q.1
What is primitive data type?
Ans.
:
Primitive data types in C are the fundamental data types such as int, float,
char and void.
The
int data type is for representing the whole number values.
Q.2
What is the difference between for and while statement ?
Ans.
:

Q.3
Explain the use of void data type.
Ans.
:
• The void data type indicates that the function is returning nothing.
•
If the function is not returning anything from the function then its data type
is specified as void.
Q.4
What is the use of arrays ?
Ans.
: Array
is used to store the elements of same data type. For storing the strings - the
arrays is used.
Q.5
Explain the concept of string in C.
Ans.
:
String is a collection of characters. For example
char
a="hello";
char
a=['h', 'e', '1', '1', 'o'];
Q.6
Differentiate between while and do-while loops.
Ans.

Q.7
What do you mean by nested loops ?
Ans.
Nested
loops mean loops within the loops. For example for nested, the loop is given
below
for
(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
printf("It's
My Life!!!");
}
}
Q.8
How will you initialize array in C ?
Ans.
There
are two ways by which an array can be initialized -
i)
Initializing an array at declaration.
ii)
Initializing an array with the help of loop.
Initializing
an array means storing some value in it at some specific location.
i)
Initializing an array at declaration -
At
declaration of an array it can be initialized..
For
example:
int
a[5] = {10, 20, 30, 40};
float
marks [8] = {33.2, 57.8, 76.5, 81.3};
ii)
Initializing array with the help of loop -
Using
for loop or while loop an array can be initialized.
For
example -
30
For
(i=0; i<5; i++)
{
scanf("%d",
&a[i]);
}
Q.9
What is the purpose of do-while statement ?
Ans.
:
The
purpose of do-while is to bring looping in programming statements. The way to
write the do... while statement is -
do
{
…
statements;
…
while
(some condition);
For
example
count
= 1
do
{
printf("\n
I am on first line of do-while");
count++;
}
while (count < = 5);
Q.10
What are the basic operations performed on an array ?
Ans.:
Array
is simply a collection of elements which are of same data type. Mainly we
can perform following operations on an array-
i)
Storing the elements in an array
ii)
Retrieving or printing elements from an array.
Following
'C' program performs these operations-
#include
<stdio.h>
#include
<conio.h>
main(
)
{
int
a[10], index;
clrscr(
);
printf
("In Store The Elements In An Array a");
for
(index = 0; index < = 9; index++)
scanf("%d",
&a[index]);//storing elements in array
printf
("\n Retrieving the array elements");
for
(index=0; index <=9; index++)
printf("%d",
a[index]); //retrieving elements from array
}
Q.11
List the primary data types in C.
Ans.
: Primary
data types in C are as given below

Q.12
What are string operations defined in C?
Ans.
: Various
string operations defined in C are
1)
strlen(): For Finding out length of string
2)
strcpy(): For copying the one string to another
3)
strcat(): For concatenating two strings
4)
strcmp(): For comparing two strings
5)
strrev(): For reversing two strings
Q.
13 What is a static variable? Give an example.
Ans.
:
Static variables are those variable that retain their values even after they
come out of the scope.
For
example
#include<stdio.h>
int
fun( )
{
static
int count = 0;
count++;
return
count;
}
int
main( )
{
printf("\n%d",fun());
printf("\n%d",fun());
printf("\n%d",fun());
printf("\n%d",fun());
return
0;
}
Output
1
2
3
4
Q.14
Write a C program to get a paragraph of text as input.
AU:
Dec.-19
Ans.
:
#include<stdio.h>
int
main( ) {
char
para[100];
printf("Enter
Paragraph: ");
scanf("%[^\t]s",
para);//accept all the characters except tab
printf("Accepted
Paragraph: %s", para);
return
0;
}
Q.15
How an n dimensional array is represented ?
AU:
May-19
Ans.
:
A multidimensional array is declared using the following syntax : type
array_name[d1][d2] [d3][d4]....................[dn];
where
each d is a dimension, and dn is the size of final dimension.
The
conceptual syntax for 3D array is this:
data_type
array_name[table][row][column];
Q.16
Differentiate between row major and column major representation of arrays.
AU:
Dec.-19
Ans.
:
In row-major order, consecutive elements of the rows of the array are
contiguous in memory; in column-major order, consecutive elements of the
columns are contiguous.
The
difference between row-major and column-major order is simply that the order of
the dimensions is reversed.
C Programming and Data Structures: Unit I: C Programming Fundamentals : Tag: : C Programming Fundamentals | C Programming and Data Structures - Two Marks Questions with Answers
C Programming and Data Structures
CS3353 3rd Semester EEE, ECE Dept | 2021 Regulation | 3rd Semester EEE Dept 2021 Regulation