C Important Question With Answer
C Important Question With Answer
C Important Question With Answer
4. Write down the syntax and give an example for array initialization.
data_type array_name[size];
Or
Data_type array_name[size 1] [size 2] [size n] ;
Eg:
#include <stdio.h>
int main()
{
// declaring array of integers
int arr_int[5];
// declaring array of characters
char arr_char[5];
return 0;
}
5. Define Array.
An array in C is a fixed-size collection of similar data items stored in contiguous memory
locations. It can be used to store the collection of primitive data types such as int, char,
float, etc., and also derived and user-defined data types such as pointers, structures, etc.
6. What is the use of preprocessor – directive?
Preprocessor directives, such as #define and #ifdef , are typically used to make source
programs easy to change and easy to compile in different execution environments.
Directives in the source file tell the preprocessor to take specific actions .
7. Keywords cannot be used as identifiers-Justify the correctness of statement.
Keywords cannot be used as identifiers for other purposes (e.g. variable/function/method
naming). Keywords are reserved words so cannot be used as identifier, but in case
sensitive languages, in which keywords are generally in lower case, so you can use
uppercase name of keyword as an identifier.
8. List out Various Input & Output Statements in C.
Basic Input And Output In C
scanf() ...
printf() ...
Integer Input: scanf("%d", &intVariable); Output: printf("%d", intVariable);
Float Input: scanf("%f", &floatVariable); Output: printf("%f", floatVariable);
PART –B
1. Explain about the various looping statement available in with appropriate sample
Programs.
Loops in programming are used to repeat a block of code until the specified
condition is met.
A loop statement allows programmers to execute a statement or group of
statements multiple times without repetition of code.
1. Entry Controlled loops: In Entry controlled loops the test condition is checked
before entering the main body of the loop. For Loop and While Loop is Entry-controlled
loops.
2. Exit Controlled loops: In Exit controlled loops the test condition is evaluated at the
end of the loop body. The loop body will execute at least once, irrespective of whether
the condition is true or false. do-while Loop is Exit Controlled loop.
Note : Write the Example Program for all the Looping
Decision-Making Statements and are used to evaluate one or more conditions and
make the decision whether to execute a set of statements or not.
These decision-making statements in programming languages decide the direction
of the flow of program execution.
Note : Explain all the statement and write a simple example programs
3. Evaluate the following expressions using operator precedence rule. Explain the order of
execution of operators.
(8*3-4) + (5%5? 3 : –9) + 5 – 20 / 10
a * b + (c / d) – 2 A 2 – (e + 4) where a = 2, b = 3, c = 8, d = 2, e = 5.
4. What is an array? Explain about One dimensional array with a sample program.
Example Program:
int main() {
//declaring and initializing one-dimensional array in C
int arr[3] = {10, 20, 30};
OutPut:
Value of arr[0]: 10
Value of arr[1]: 20
Value of arr[2]: 30
5. Write a C program to read N integers into an array A and to find the Output the results
computed with appropriate headings
(i)sum of odd numbers,
#include<stdio.h>
Void main()
{
int a[10],i,sum=0;
printf("Enter upto 5 Values: ");
for(i=0; i<5; i++)
scanf("%d",&a[i]);
for(i=0; i<5; i++)
{
if(a[i]%2==1)
sum=sum+a[i];
}
printf("Sum of Odd values is: %d ",sum);
}
Output:
Enter upto 5 Values: 2 3 5 4 7
Total Sum of Odd values is: 15
#include <stdio.h>
int main ()
{
int mat1[3][3] = { {0, 1, 2}, {3, 4, 5}, {6, 7, 8} };
int mat2[3][3] = { {9, 10, 11}, {12, 13, 14}, {15, 16, 17} };
int sum[3][3], i, j;
return 0;
}
OutPut:
matrix 1 is :
0 1 2
3 4 5
6 7 8
matrix 2 is :
9 10 11
12 13 14
15 16 17
15 17 19
21 23 25
PART -C
1. Write a C program to demonstrate the working concept of operators.
An operator in C can be defined as the symbol that helps us to perform some specific
mathematical, relational, bitwise, conditional, or logical computations on values and
variables.
The values and variables used with operators are called operands. So we can say that the
operators are the symbols that perform operations on operands.
Types of Operators in C
1. Arithmetic Operators
2. Relational Operators
3. Logical Operators
4. Bitwise Operators
5. Assignment Operators
6. Other Operators
Note: Explain all the Operator concepts and simple example program
2. What is string? Write a C program that reads a sentence and prints the frequency of
each of the vowels and total count of consonants.
#include<stdio.h>
void main()
{
int i,cons=0,vow=0;
char a[100];
printf("Enter the sentence\n");
gets(a);
for(i=0;a[i]!='\0';i++)
{
if(a[i]=='a'||a[i]=='A')
vow=vow+1;
else if(a[i]=='e'||a[i]=='E')
vow=vow+1;
else if(a[i]=='i'||a[i]=='I')
vow=vow+1;
else if(a[i]=='o'||a[i]=='O')
vow=vow+1;
else if(a[i]=='u'||a[i]=='U')
vow=vow+1;
else
cons=cons+1;
}
printf("vowel count= %d\n",vow);
printf("consonants count = %d\n",cons);
}
Output :
Enter the sentence
Hello
vowels count = 2
consonants count = 3