Professional Documents
Culture Documents
Dca1102 C Language
Dca1102 C Language
Dca1102 C Language
d) None of these.
Ans: a
Ans: a
Ans: b
5. C is a ___ language
a) High Level
b) Low Level
Ans: c
Ans: d
Ans: b
Ans: d
Ans: d
Ans: d
Ans: a
12. Character constants should be enclosed between ___
a) Single quotes
b) Double quotes
c) Both a and b
d) None of these
Ans: a
Ans: b
14.The __________ consists of an equal sign and an expression, which is usually a single
constant.
a) Initializer
b)Variable
c) Constant
d) None of these
Ans: a
15. A single declaration statement can contain variables of different types. (True/False)
Ans: False
Ans: Underscore
21.Using C language programmers can write their own library functions. (True/False)
Ans: True
Ans:True
Ans: False
31. An octal integer constant consists of any combination of digits from the set _________
through _________.
Ans: (0,7)
34. The size of the Integers in C language is same in all the machines. (True/False)
Ans: True
37. Which of the following tells the compiler the name and type of a variable you'll be using in
your program?
(a) declaration
(b) variables
(c) integers
(d) assignments
Ans: a
a) Additional
b) Subtraction
c) Multiplication
d) Modulus
Ans: d
47. The logical operators ___________ and __________ are used when we want to test more
than one condition and make decisions.
Ans: &&, ||
Ans: Incorrect
49. ____________________ are built-in functions that carry out various commonly used
operations or calculations
Ans: Library Function
50. Fill in the blanks as indicated by alphabets. The value of (a) floor(5.8),
(b) floor(-5.8), (c) ceil(5.8) and (d) ceil(-5.8) are ______ (a) _____,
____ (b) ______, ____ (c) _______ and _____ (d) ______ respectively.
52. Which pair of functions below are used for single character I/O.
a) Getchar() and putchar()
b) Scanf() and printf()
c) Input() and output()
d) None of these
Ans: a
a) C
b) A
c) a
d) none of these
Ans: c
56. gets() is a formatted input statement. (True/False)
Ans: False
57. The argument for a gets() and puts() functions are ____________variables.
a) char
b) String
c) Integer
d) Float
Ans: b
58. Using gets() function, you cannot include whitespace characters in the input string.
(True/False).
Ans: False
63. When the accuracy provided by a float number is not sufficient, the type long float can be
used to define the number. (True/False)
Ans: False
65. If the operands are of different data types, the ‘lower’ type is automatically converted to the
‘higher’ type before the operation proceeds. (True/False)
Ans: True
66. During the final assignment ________ to int causes dropping of the excess higher order
bits.
a) int
b) short int
c) long int
d) all of these
Ans: c
Ans: 2.2
70. If the value of X is 35.2, then the value of A in the expression: A = (int)(X+0.5); is
____________.
a) 35
b) 35.7
c) 36
d) None of these
Ans: a
71. What is the format character to display the value of a char variable?
a) %d
b) %f
c) %c
d) %s
Ans: c
Ans: False
76. In order to stop reading the input character, you can use a value called___________.
Ans: EOF
77. The __________ string consists of control characters, whitespace characters, and non-
whitespace characters.
Ans: Control
81. To print an int argument in octal, you can use ____________ format string.
a) %u
b) %i
c) %x
d) %o
Ans: d
83. malloc() function used in dynamic allocation is available in which header file?
a) stdio.h
b) stdlib.h
c) conio.h
d) mem.h
Ans: b
86. If the function is defined elsewhere (not in the same program where it is called), the function
prototype must be preceded by the keyword
Ans: Extern
_____________.
91. Which of the following header file is required for strcpy() function?
a) string.h
b) strings.h
c) files.h
d) strcsspy()
Ans: a
93. Closing a file simply involves calling fclose with the ___________ as its argument.
Ans: File pointer
94. If you forget to close a file, it will be closed automatically when the program exits.
(True/False)
Ans: True
95. The companion function to putchar is putc, and the file pointer argument comes first.
(True/False)
Ans: false
100. The library function used to copy one string to another is_________________.
Ans: strcpy
101. The library function atoi can be used for any string. (True/False)
Ans: False
105. In C, a Union is
a) memory location
b) memory store
c) memory screen
d) None of these
Ans: b
106. When the main function is called, it is called with the arguments
a) argc
b) argv
c) None of these
d) both a & b
Ans: d
109. The return data type, function name and the list of formal parameters enclosed in brackets
are separated by _______________.
Ans: Comma
112. The function prototypes of the library functions is in the corresponding__________ files.
Ans: Header
113. The function prototype for the function fun() called in main() below is________________ .
Ans: double fun(double, double);
114. ______________ is a process by which a function calls itself repeatedly, until some
specified condition is satisfied
Ans: Recursion
116. A Structure
a) can be read as a single entity
b) cannot be read as a single entity
c) can be displayed as a single entity
d) has member variables that cannot be read individually
Ans: b
118. The process of translating a source program into machine language is a function
of:
a) Compiler
b) Translator
c) Assembler
d) None of these.
Ans: a
119. _________________ let you work with the individual bits of a variable; one common use is
to treat an integer as a set of single-bit flags.
a) Bitwise operator
b) Logical Operator
c) Relational operator
d) None of these
Ans: a
122. The prefix form to increment i is _______ whereas the postfix form to increments i is
________.
Ans: ++i, i++
127. The goto requires a _________ in order to identify the place where the
branch is to be made.
Ans: Label
129. The series of statements enclosed by braces after the expression in simple if statement is
itself a simple expression statement. (True/False)
Ans: False
130. In the cascaded if/else/if/else/... chain, each else clause is another _______ statement.
Ans: If
138. C supports the ______ statement to branch unconditionally from one point to another in
the program.
a) continue
b) goto
c) break
d) for
Ans: b
140. On using the ________, the body of the loop is always executed at least once irrespective
of the expression.
Ans: Do….while
143. The “control variable'' of a for loop does not have to be an integer. (True/False)
Ans: True
#include<stdio.h>
Ans: 15
146. Which one of the following is a loop construct that will always be executed once?
a. for
b. while
c. switch
d. do while
Ans d
a. Before main
b. After main
c. Anywhere, but starting on a new line.
d. None of the these.
Ans c
148. What is the result after execution of the following code if a is 10, b is 5, and c is 10?
If ((a > b) && (a <= c))
a = a + 1;
else
c = c+1;
a. a = 10, c = 10
b. a = 11, c = 10
Ans: b
149. How many characters can a string hold when declared as follows?
char name[20]:
a. 18
b. 19
c. 20
d. None of the these
Ans: c
150. What is the maximum number of characters that can be held in the string variable char
address line [40]?
a. 38
b. 39
c. 40
d. 41
Ans: b
152. Does an automatic variable retain its value once control is transferred out of its defining
function? (Yes/No)
Ans: No
153. The key word auto is must in the declaration of automatic variables. (True/False)
Ans: False
154. The variables declared in the main() function are the global variables.(True/False)
Ans: False
155. The global variables are more secured than the automatic variables in a program.
(True/False)
Ans: False
156. The scope of static variables and automatic variables is the same. (True/False)
Ans: True
159. What will the result of len variable after execution of the following statements?
int len;
char str1[] = {"39 march road"};
len = strlen(str1);
a. 11
b. 12
c. 13
d. 14
Ans c
Ans b
1. x - = y + 1;
a. x = x - y + 1
b. x = -x - y - 1
c. x = x + y - 1
d. x = x - y - 1
Ans d
a. Hello, World!
b. Hello,
World!
c. Hello
d. Compile error
Ans B
163. By modularizing the problem into different sub problems. Each sub problem can be
implemented as a __________.
Ans: Function
Ans: False
165. The visibility of a variable determines how much of the rest of the program can access that
variable. (True/False)
Ans:True
166. __________ class refers to the persistence of a variable and its scope within the program,
that is, the portion of the program over which the variable is recognized.
Ans: Storage
167. Visibility provides security for your data used in a program. (True/False)
Ans:True
168. The main purpose of using external variables is to access the same variable in different
______________ files.
Ans: Source
169. Compiler doesn’t allocate memory for an external variable where it is accessed.
(True/False)
Ans:True
170. Global variables and external variables have the same scope. (True/False)
174. Suppose that cPtr is a character pointer, and its current content is 300. What will be the
new value in cPtr after the following assignment?
cPtr = cPtr + 5;
a. 305
b. 310
c. 320
d. 340
Ans a
a. Non-linear
b. Primary
c. Linear
d. Data type
Ans c
a. In the array, users can only allocate the memory at the run time.
Ans: b
177. In a two-dimensional matrix, the first subscript in the declaration specifies number of
__________.
Ans: Rows
199. Will there be a compilation error for the following program? (Yes/No).
char str1[10];
str1=”Hello, world”;
printf(“%s”, str1);
200. The contents-of operator * does not merely fetch values through pointers; it can also set
values through pointers. (True/False)
Ans: True
201. You can perform any type of arithmetic operation on pointers. (True or False)
Ans: False
202. For an int array a[10], If you declare a pointer variable ip then you can set it to point to the
beginning of an array by assigning: int *ip =____________ .
Ans: &a[0];
203. One common use of pointer comparisons is when copying arrays using pointers.
(True/False)
Ans: True
204. To increment what p points to, you can use the expression __________.
Ans: (*p)++.)
a. 1.8
b. 1.0
c. 2.0
d. None of the these
Ans: d
Ans: a
a. Compiler
b. Computer
c. Compiler library
d. Users
Ans: d
210. Which of the following function is used to write the integer in a file?
a. getw()
b. putw()
c. int value
d. f_int()
Ans: b
211. A ______ is a special pointer value that is known not to point anywhere.
Ans: Null pointer
212. A function that returns ____________ values can return a null pointer when it is unable to
perform its task.
Ans: Pointer
213. In general, C does not initialize pointers to null for you, and it never tests pointers to see if
they are null before using them. (True/False)
Ans: True
215. You can represent an array of strings using pointers by using an array of __________ to
character.
Ans: Pointers
Ans: Null
217. Which of the following statement is correct about the ftell() function?
Ans: a
218. In which of the following modes, the user can read and write the file?
Ans: c
219. The enum keyword is used to assign names to the ________ constants.
a. Integer
b. String
c. Character
d. All of the these
Ans: a
220. Which of the following operator's precedence order is correct (from highest to lowest)?
a. %, *, /, +, -
b. %, +, /, *, -
c. +, -, %, *, /
d. %, +, -, *, /
Ans: a
221. We can define a two dimensional array as a pointer to a group of contiguous _________
dimensional arrays.
Ans: One
222. A two-dimensional array can also be expressed in terms of an_________ of pointers rather
than as a pointer to a group of contiguous arrays.
Ans: Array
223. A ___________ is a convenient tool for handling a group of logically related data items.
Ans: structure
224. We can declare structure variables using the tag name anywhere in the program.
(True/False)
Ans: True
226. If person1 and person2 are variables of the same type structure then the expression
person1>person2 is valid. (True/False)
Ans: False
228. The link between a member and a variable is established using the member operator
_________.
Ans: Dot(.)
a. x * = 65;
b. x / = 42;
c. x % = 2;
d. x ! = 56;
Ans: d
a. ==
b. ++
c. ||
d. &&
Ans: a
a. un
b. unt
c. ion
d. union
Ans: d
a. For
b. for
c. Basic salary
d. hello.
Ans: a
234. We can modify a member of the structure by passing the structure as a_____________.
Ans: argument
235. We can use structures to describe the format of a number of related variables.
(True/False)
Ans: True
236. You can declare an array of structures where each element is defined to be of the type
_______.
Ans: struct
237. The parentheses around the de referenced pointer is necessary to enforce the correct
_______.
Ans: precedence
238. An alternative notation other than dot, permits simpler pointer access to structure members
is ____________.
Ans: ->
240. The compiler allocates storage for the smallest member of the union. (True/False)
Ans: false
241. Which of the following header files is used for character type function in C language?
a. <assert.h>
b. <ctype.h>
c. <iostream.h>
d. <locale.h>
a. *
b. #
c. &
d. &&
Ans: a
247. Defining instances of global variables is not recommended in the header files. (True/False)
Ans: True
253. You can use _______________ directive which compiles code depending on whether a
compile-time expression is true or false.
Ans: #if
Ans: d
void show()
{
printf("AFRICA ");
}
A) ARGENTINA AFRICA
B) AFRICA ARGENTINA
C) ARGENTINA
D) Compiler error
Ans: b
262. The function that is used to alter the size of a block previously allocated is
______________.
Ans: realloc()
263. A linked list is a data structure that is used to model a dynamic list of data items and is a
collection of ___________.
Ans: nodes.
return 0;
}
A) 25 1234
B) 25 0
C) 25 25
D) Compiler error
Ans: c
269. We may add a “+’’ character to the mode string in the fopen function to indicate that we
want to both read and write. (True/False)
Ans: True
270. __________ returns non-zero if the stream's error indicator is set, zero otherwise.
Ans: ferror
271. ____________ function returns the current value (measured in characters) of the file
position indicator if stream refers to a binary file.
Ans: ftell
272. fseek allows the file position indicator for stream to be set to an arbitrary value.
(True/False)
Ans: True
273. __________ stores the current file position indicator for stream in the object pointed to by
pos.
Ans: fgetpos
274. Command line argument is a parameter supplied to a program when the program is
invoked. (True/False)
Ans: true
275. In the command line arguments of main(), argv is an array-of-pointers to-___________.
Ans: char
282. A ___________ image is one in which each pixel on the screen is set individually.
Ans: Bitmapped
283. The best solution to allocate memory locations for the objects when the actual number of
locations is not known in advance is by using__________________ memory allocations.
288. In a linked implementation of a queue, the newly added element is the front element.
(True/False)
Ans: False
a) 8
b) 16
c) 64
d) 80
Ans: d
Ans: True
a) -128 to 127
b) 128 to 127
c) 1 to 127
Ans: a
Ans: false
Ans: false
295. getchar(),putchar(), scanf(), printf(), gets() and puts(). These functions can be
a) stdio.h
b) math.h
c) conio.h
d) ctype.h
Ans: a
299. A method where the youngest entry or ‘top of the stack is processed first is termed as
Ans: d
Ans: a
Q1 Write a program to accept a number and check the number is even or odd?
Ans: #include<stdio.h>
int main()
int number;
printf("Enter a number:");
scanf("%d",&number);
if(number%2==0)
else
return 0;
Q2. Write a program to accept three number and find out the largest of three number.
int main()
int a, b, c;
scanf("%d %d %d",&a,&b,&c);
printf("%d is largest",a);
printf("%d is largest",b);
printf("%d is largest",c);
Q3. Write a program to accept the marks and check the grade depends of a condition
(marks >85 display grade A,marks >60 display grade B+, marks>40 display grade B,
marks>30 display grade C, other wise display fail).
int main()
int marks;
scanf("%d",&marks);
else
Ans: Constants in C refer to fixed values that do not change during the execution of a program. C
supports several types of constants:
1. Integer constants
An integer constant refers to a sequence of digits. There are three types of integers, namely decimal,
octal and hexadecimal.
Decimal integers consist of a set of digits, 0 through 9, preceded by an optional – or +.
Examples: 12, -546, 0, 354647, +56
2. Real constants
The numbers containing fractional parts like 67.45 are called real (or floating point) constants.
Examples: 0.0045, -8.5, +345.678
3. Character constants
A single character constant (or simple character constant) contains a single character enclosed within a
pair of single quote marks.
Examples: ‘6’, ‘X’, ‘;’
4. String constants
A string constant is a sequence of characters enclosed within double quotes.The characters may be
letters, numbers, special characters and blank space.
Examples: “Hello!”, “1947”, “5+3”
Q5. Write a program to accept a year and check the year is leap year or not a leap year.
Ans:
#include<stdio.h>
#include<conio.h>
int main()
{
int year;
printf("Enter Year: ");
scanf("%d", &year);
if((year%4==0) && (year%100!=0))
printf("\nIt's a Leap Year");
else if(year%400==0)
printf("\nIt's a Leap Year");
else
Ans: #include<stdio.h>
#include<conio.h>
int main()
{
float fahrenheit, celsius;
printf("Enter Temperature Value (in Fahrenheit): ");
scanf("%f", &fahrenheit);
celsius = (fahrenheit-32)/1.8;
printf("\nEquivalent Temperature (in Celsius) = %0.2f", celsius);
getch();
return 0;
}
An operator is a symbol that tells the computer to perform certain mathematical or logical manipulations.
Operators are used in programs to manipulate data and variables. There are very types of operator:
1. Arithmetic operators
2. Unary operator
3. Relational operators
4. Logical operators
5. Conditional operator
6. Bitwise operators
7. Increment and Decrement operators
1. Arithmetic Operators
The basic operators for performing arithmetic are the same in many computer languages:
+ addition
- subtraction
* multiplication
/ division
% modulus (remainder)
2. Unary Operator
A unary operator acts upon a single operand to produce a new value. Example (++,--)
3. Relational
4. Logical operators
You can also combine true/false values by using the Boolean operators(also called the logical
operators), which take true/false values as operands and compute new true/false values. The three
Logical operators are:
&& AND
|| OR
! NOT (takes one operand, “unary'')
Q8. Write a program to accept a number and find out a factorial number.
Ans:
#include<stdio.h>
#include<conio.h>
int main()
{
int num, i, fact=1;
printf("Enter any number: ");
scanf("%d", &num);
for(i=num; i>0; i--)
fact = fact*i;
printf("\nFactorial of %d = %d", num, fact);
getch();
return 0;
}
Q10. Write a program to accept a number and find out a factorial number using function.
Ans:
#include<stdio.h>
#include<conio.h>
int findFact(int);
int main()
{
int num, fact;
printf("Enter any number: ");
scanf("%d", &num);
fact = findFact(num);
printf("\nFactorial of %d = %d", num, fact);
getch();
return 0;
}
int findFact(int n)
{
int i=n, f=1;
while(i>0)
{
f = f*i;
i--;
}
return f;
}
Q11. write a program that will calculate the factorial of any given number using recursive
function?
Ans: #include<stdio.h>
#include<conio.h>
int findFact(int);
int main()
Q12. Write a program to accept a character value and check the character value is vowel
or consonant. (using switch statement)
Ans:
#include <stdio.h>
int main()
char input;
switch ( input )
case 'a':
break;
case 'e':
break;
break;
case 'o':
break;
case 'u':
break;
case 'A':
break;
case 'E':
break;
case 'I':
break;
case 'O':
break;
case 'U':
break;
default:
printf( "Consonant" );
return 0;
Q13. Write a program to accept a character value and check the character value is vowel
or consonant. (using if statement)
Ans:
#include <stdio.h>
int main()
char input;
if(input == ‘a’ || input == ‘A’ || input == ‘e’ || input == ‘E’ || input == ‘i’ || input == ‘I’ || input == ‘o’
|| input == ‘O’ || input == ‘u’ || input == ‘U’ )
else
printf( "Consonant" );
return 0;
Ans:
Void main()
int count;
sum = 0;
count = 0;
while (count<N)
Printf(“enter a number”);
scanf(“%f”, &number);
count = count + 1;
average = sum / N;
Q15. write a program to accept any number and check number is prime or not.
Ans:
#include<stdio.h>
#include<conio.h>
int main()
{
int num, i, count=0;
printf("Enter a number: ");
scanf("%d", &num);
for(i=2; i<num; i++)
{
if(num%i == 0)
Ans:
#include<stdio.h>
#include<conio.h>
void main()
clrscr();
scanf(“%d”,&n);
large=0;
i=0;
while(i<n)
scanf(“%d”, &num);
if(large<num)
large=num;
i++;
Ans:
#include <stdio.h>
Void main()
int i, j, m, n;
for(i=0;i<m;i++)
for(j=0;j<n;j++)
scanf(“%d”, &a[i][j]);
for(i=0;i<m;i++)
for(j=0;j<n;j++)
scanf(“%d”, &b[i][j]);
for(i=0;i<m;i++)
for(j=0;j<n;j++)
c[i][j] = a[i][j]+b[i][j];
for(i=0;i<m;i++)
for(j=0;j<n;j++)
printf(“%d\t”, c[i][j]);
printf(“\n”);
Q18. Write a program to accept two number and swap the two number.
Ans: #include<stdio.h>
#include<conio.h>
int main()
{
int num1, num2, temp;
printf("Enter Two Numbers:-\n");
printf("First Number: ");
scanf("%d", &num1);
printf("Second Number: ");
scanf("%d", &num2);
printf("\nBefore Swap:\n");
printf("First Number = %d\tSecond Number = %d", num1, num2);
temp = num1;
num1 = num2;
num2 = temp;
printf("\n\nAfter Swap:\n");
printf("First Number = %d\tSecond Number = %d", num1, num2);
getch();
return 0;
}
#include<stdio.h>
#include<conio.h>
int main()
{
int num, rev=0, rem, temp;
printf("Enter a Number: ");
scanf("%d", &num);
temp = num;
while(temp>0)
{
rem = temp%10;
rev = (rev*10)+rem;
temp = temp/10;
}
if(rev==num)
printf("\nIt's a Palindrome Number");
else
printf("\nIt's not a Palindrome Number");
getch();
return 0;
}
Ans:
#include<stdio.h>
main()
int a, b;
int temp;
temp=*x;
*x=*y;
*y=temp;
return;
Ans: #include<stdio.h>
#include<conio.h>
int main()
{
int i, j;
for(i=0; i<5; i++)
{
for(j=0; j<=i; j++)
printf("* ");
printf("\n");
}
getch();
return 0;
}
Output
Ans:
#include<stdio.h>
#include<conio.h>
int main()
{
int arr[10], i, large;
printf("Enter 10 Array Elements: ");
for(i=0; i<10; i++)
scanf("%d", &arr[i]);
i=0;
large = arr[i];
while(i<10)
{
if(large<arr[i])
large = arr[i];
i++;
}
printf("\nLargest Number = %d", large);
getch();
return 0;
}
Q24. Write a program to accept name and find out of length of name.
Ans:
#include<stdio.h>
#include<conio.h>
#include<string.h>
int main()
{
char str[20];
int len;
printf("Enter the string: ");
gets(str);
len = strlen(str);
printf("\nLength of the string = %d", len);
getch();
return 0;
}
Ans:
#include<stdio.h>
#include<conio.h>
#include<string.h>
int main()
{
char str1[50], str2[50];
printf("Enter first string: ");
gets(str1);
printf("Enter second string: ");
gets(str2);
strcat(str1, str2);
printf("\nString after concatenation is:\n%s", str1);
getch();
return 0;
}
Ans:
#include<stdio.h>
int main()
int n1=0,n2=1,n3,i,number;
scanf("%d",&number);
n3=n1+n2;
printf(" %d",n3);
n1=n2;
n2=n3;
return 0;
Q27. To print the Name, Salary and date of joining of a person.(using Structures)
Ans:
#include<conio.h>
#include<stdio.h>
struct personal
char name[30];
int day;
int month;
int year;
float salary;
};
void main()
struct personal p;
gets(p.name);
scanf(“%d”,&p.day);
scanf(“%d”,&p.month);
scanf(“%d”,&p.year);
printf(“\nName:",p.name);
printf(“Salary:",p.salary);
getch();
1
12
123
123 4
Ans:
#include <stdio.h>
int main() {
int i, j, rows;
scanf("%d", &rows);
printf("\n");
return 0;
1
22
333
4444
Ans:
#include <stdio.h>
int main() {
int i, j, rows;
scanf("%d", &rows);
printf("\n");
return 0;
Ans:
Structure
A structure is a user-defined data type available in C that allows to combining data items of
different kinds. Structures are used to represent a record.
Defining a structure: To define a structure, you must use the struct statement. The struct
statement defines a new data type, with more than one member. The format of the struct
statement is as follows:
struct [structure name]
{
member definition;
union
A union is a special data type available in C that allows storing different data types in the same
memory location. You can define a union with many members, but only one member can
contain a value at any given time. Unions provide an efficient way of using the same memory
location for multiple purposes.
Defining a Union: To define a union, you must use the union statement in the same way as
you did while defining a structure. The union statement defines a new data type with more than
one member for your program. The format of the union statement is as follows: