0% found this document useful (0 votes)
5 views

CIMP -Day 1

The document provides a comprehensive overview of various programming concepts in C, including algorithms for calculating the area of a circle, operator precedence, file operations, pointers, branching statements, and the general structure of a C program. It also differentiates between searching and sorting, explains variable rules, lists various operators, and discusses pre-processor directives and features of C. Additionally, it compares while and do-while loops, explains flowchart symbols, and contrasts characters with strings, recursion, arrays, and structures.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

CIMP -Day 1

The document provides a comprehensive overview of various programming concepts in C, including algorithms for calculating the area of a circle, operator precedence, file operations, pointers, branching statements, and the general structure of a C program. It also differentiates between searching and sorting, explains variable rules, lists various operators, and discusses pre-processor directives and features of C. Additionally, it compares while and do-while loops, explains flowchart symbols, and contrasts characters with strings, recursion, arrays, and structures.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

Frequently Asked Questions

1. Write algorithm, flow chart and program to find the area of a circle.
Answer:
Algorithm findcirclearea
Begin
Declare the r as integer
Declare the pi=3.14,area as float
Print”Enter the value of r”
Read the value of r;
Calculate area=pi*r*r
Print the value of area
End
// Draw the flowchart

// Online C compiler to run C program online


#include <stdio.h>

int main() {
// Write C code here
int radius;
float pi=3.14,area;
printf("Enter the radius value");
scanf("%d",&radius);
area=pi*radius*radius;
printf("The area =%f",area);

1|Page
return 0;
}
Enter the radius value5
The area =78.500000

2. What is operator precedence? Which operator in C has highest


precedence?
Answer: Operator precedence defines the order in which operators are
evaluated in expressions.
 The operator with highest precedence will be evaluated first and then the
next precedence
 The unary dereference operator (*), which is used for pointer
dereferencing, has the highest precedence

3. Define File and write about file operations.


Answer:
 File is a collection of data stored on a secondary storage device,
such as a hard disk or flash drive.
 Files can be used to store information persistently, allowing
programs to read from and write to them
 File operations in C involve various functions from the Standard
I/O Library #include<stdio.h> and #include<file.h>.
 File Operations: file open, file read, file write, file append, file
close and so on.
4. Define pointers with its syntax
Answer: pointer is a variable that holds the memory address of another
variable, enabling indirect access to the data.
Pointers uses & to pass the address of the variable from actual to formal
parameters
It uses * to access the value with in the address of the variable
Syntax
Int i=10;
Int p=&I;
Printf(“The address of I is =%u”,&i);
Printf(“The value of I is =%d”,*p);

2|Page
5. List the tokens in C, and explain in detail about them.
Answer:

6. What is branching in c? What are the types of branching statements?


Explain in detail.
Answer:
Branching in C refers to the ability to make decisions and execute different
code blocks based on certain conditions. C provides types of branching
statements like if, else, switch, and goto
//Simple If Statement
if (condition) {
// stmt 1;

3|Page
}
//If Else
if (condition) {
// stmt 1;
} else {
// stmt 2;
}
//Nested If - else
if (condition1) {
// stmt 1;
} else if (condition2) {
//stmt 2;
} else {
// stmt 3;
}
switch (expression) {
case case1:
// stmt 1;
break;
case case2:
// stmt 2;
break;
// More cases...
default:
// wrong case
}
7. What is the general structure of `C' program and explain with
example?
Answer:
//pre-processor directives
// global variables
#include<stdio.h>
Void main()
{
//data types and variable declarations
Int a,b,c;
Function();//function calls
//Statements;
}

4|Page
Function()
{
//local variables
//statements
//return statements
}

8. Differentiate searching and sorting?


Answer:
Searching means finding the key element with in a given array of numbers
Type of Searching’s: Linear search: compare the key element from the a[0]
element to a[n-1] element and print if the element is found otherwise not
found
Linear search best case is O(1), average case is O(n/2) and worst case is
O(n).
Binary search: Assign low=a[0], high=a[n-1] mid=(low+high)/2
compare if (key==a[mid] )return found
else if (key<a[mid]) search left array
else search right array
Best case O(1) average and worst case O(n/2)
Sorting: Arranging the numbers in either ascending and descending
order with in a array of elements
Types of sortings
Bubble sort and selection sort

9. What is a variable? And write the rules for constructing variable?


Answer: Variable is the storage location where the value is stored and
manipulated.
Rules to construct the variable:
- It cannot be key word or reserved word
- It is case sensitive example : int A,a
- Variable can be of any length but it is advise to follow short variables
- It contains alphanumerical characters int a12
- Variable name should be meaning full
- A variable name in C must begin with a letter (uppercase or lowercase) or
an underscore (_). It cannot start with a digit.
10.List various operators in C language.

5|Page
Answer:
Operator name Operator symbol
Arithmetic +, -, *, /, %
Relational <, <=, >, >=, ==, !=
Logical &&, ||, !
Assignment =
Bitwise & , |, !
Conditional ?:
Size of Sizeof();

11.Write in detail about Pre-processor directives.


Answer: Pre-processor is the code is added to the program before its
execution. Pre-processor of two type’s system pre-processors: Those are
defined by the compilers like #include<stdio.h> #include<file.h>
#include<string.h>
User defined pre-processors These are define by users
#define ‘Directive’ #undef ‘Directive’, macros
12.What are the features of C Languages?
Answer: Features
 Structured
 Middle Level
 Top down design
 Procedure oriented
 Efficient
 Modular
 Portability
 User friendly
13.Compare While and do-While statements in C.
Answer:
 In a while loop, the condition is checked before the loop body execution.
It executes none of the false iteration
int i = 0;
while (i < 5) {
printf("%d ", i);
6|Page
i++;
}
 In a do-while loop, the loop body is executed at least once before
checking the condition. It executes at least one false iteration
do {
// code to be executed
} while (condition);
14.Explain the Symbols in a Flow chart?
Answer: Flowchart is a pictorial representation to solve a problem
Various symbols used like

15.What is the difference between C character and C string?


Answer: Character can be single digit, capital alphabet or small alphabet,
any special symbol _, &, $ and other
Char occupies 1 Byte of memory
Example: char a=’A’;
String is a collection or group of characters or char array
Example: char a[10]=”Hello”;

7|Page
16.What is recursion and write its advantages.
Answer: Recursion
 The function call by its self
 The function call contains the base condition till it satisfies the
function executes
Advantages
 It breaks the program into smaller programs
 Complexity is reduced
 Problems can be solved like Fibonacci, binary search, GCD, factorial
and others
17.
18.Review the arrays and how is different from structures
Answer:
Arrays Structures
Array is a collection of similar data
Structures is a collection of
types values with same name different data types
Int a[10]; Struct student
Array stores the values sequentially{
a[0],a[1],a[2] --- a[n-1] Int ID;
Char name[10];
Char gender;
Char address[10];
Int m1,m2,m3;
Flaot avg;
} s1,s2;
Contiguous memory allocation for Members may have different data
elements of the same data type. types, and memory is allocated
separately for each member.

8|Page

You might also like