You are on page 1of 9

Unit I - BASIC C PROGRAMMING

Part -A
1. What is meant by Structured Programming?
 Structured Programming is a type of programming that generally converts large or complex
programs into more manageable and small pieces of code.
 These small pieces of codes are usually known as functions or modules or sub-programs of
large complex programs.
 It is known as modular programming and minimizes the chances of function affecting
another.
2. Give the structure of C program.

3. What are the main features and applications of C language?


 Case sensitive: C is case sensitive language.
 Modularity: we can split the C program into number of modules. It allows reusability of
modules.
 Middle level language: as a middle level language C combines both the advantages of
low level and high level languages. (arrays, pointers etc). Efficient Use of Pointers
 General purpose programming language: C can be used to implement any kind of
applications such as maths oriented, graphics, and business oriented applications.
 Portability: we can compile or execute C program in any operating system (unix, dos,
windows).
 Powerful programming language: C is very efficient and powerful programming
language; it is best used for data structures and designing system software.
4. Define Compilation process.
Compilation refers to the processing of source code files (.c, .cc, or .cpp) and the creation
of an 'object' file. This step doesn't create anything the user can actually run. Instead, the
compiler merely produces the machine language instruction that correspond to the source
code file that was compiled.
5. What is meant by linking process?
Linking refers to the creation of a single executable file from multiple object files. In this
step, it is common that the linker will complain about undefined functions. During
compilation, if the compiler could not find the definition for a particular function, it would
just assume that the function was defined in another file. If this isn't the case, there's no way
1
the compiler would know it doesn't look at the contents of more than one file at a time. The
linker, on the other hand, may look at multiple files and try to find references for the
functions that weren’t mentioned.
6. What is a Variable? Illustrate it with an example.
A Variable is defined as a meaningful name given to a data storage location in computer
memory. A variable is an entity whose value can vary during the execution of a program. It can
be assigned different values at different times during program execution. The name if the
variable can be chosen by programmer in a meaningful way so as to reflect its function in the
program.
Example: int i, num; //i, num are variables that can store integer values
7. What is the importance of keywords in C?
Keyword is a reserved word that has a particular meaning in the programming language.
A keyword cannot be used as an identifier name in C. There are 32 valid keywords available
in C.
The basic instructions are built up using a reserved set of words, such as main, for, if,
while, default, double, extern, for, and int, etc., C demands that they are used only for giving
commands or making statements.
8. What is syntax?
Syntax is the ‘grammar’ of the programming language. It specifies the formal rules
governing the way the vocabulary elements of the language can be combined to form
instructions. The syntax of a programming language defines exactly what combinations of
letters, numbers, and symbols can be used in a programming language. During compilation,
all syntax rules are checked. If a program is not syntactically correct, the compiler will issue
error messages and will not produce object code.
9. What are the different data types available in C?
Data type is one of the most important attributes of an identifier. It determines the possible
values that an identifier can have and the valid operations that can be applied on it.
Basic/Primitive Data Types: char, int, float, double and void.
Derived Data Types: Array, pointer and function.
User-defined Data Types: Structure, Union and Enumeration
10. What are the I/O Functions in C?
Formatted I/O Statements: scanf(),printf()
Unformatted I/O Statements: getchar(), putchar(), gets(), puts()
11. What is preprocessor? or Define preprocessor.
The preprocessor is a program that process the source code before it passes through the
complier. It operates under the control of preprocessor directives which is placed in the
source program before the main( ). Commands used in preprocessor are called preprocessor
directives and they begin with “#” symbol.
12. What are an Operator, Operand and Keywords?
Operator: An operator is a symbol that specifies an operation to be performed on operands.
Example: *, +, -, / are called arithmetic operators.
Operand: The data items that operators act upon are called operands.
Example: a+b; In this statement a and b are called operands.
Keywords: Keywords are certain reserved words that have standard and pre-defined
meaning in C. These keywords can be used only for their intended purpose.
Eg: if, else, typedef, static
2
13. What are various types of C operators?
 Arithmetic Operators
 Increment and Decrement Operators
 Assignment Operators
 Relational Operators
 Logical Operators
 Conditional Operators
 Bitwise Operators
14. What is Ternary operator or Conditional operator? (or) Give an example for Ternary
operator.
Ternary operator is a conditional operator with symbols? and :
Syntax: test ? expression1 : expression2
test-Any Boolean expression.
expression1-An expression returned if test is true.
expression2-An expression returned if test is false.
#include<stdio.h>
void main()
{
int a,b,c;
printf("Enter the values of a and b:");
scanf("%d%d"&a,&b);
c = a>b ? a : b;//Ternaryoperator
printf("Larger number=%d" ,c);
}
Output
Enter the values of a and b: 30 90
Larger number=90
15. What are the Bitwise operators and logical operators available?
Bitwise operators
& - Bitwise AND
| - Bitwise OR,
~ - One’s Complement,
>> - Right shift,
<< - Left shift,
^- Bitwise XOR
Example: k=~j; where ~ take one’s complement of j and the result is stored in k.
Logical operators:
&&- Logical AND
|| - Logical OR
! - Logical NOT
16. What is the difference between while loop and do…while loop? or Differentiate Entry
and Exit controlled constructs.
While do-while
It is an entry controlled loop It is an exit controlled loop
In the while loop the condition is first In the do…while loop first the statement is
executed. If the condition is true then it executed and then the condition is checked.
executes the body of the loop. When the The do…while loop will execute at least one
condition is false it comes of the loop time even though the condition is false at the
very first time
3
Syntax: Syntax:
while(condition) do
{ {
//body of the loop //body of the loop
} } while(condition);
17. Why do we have a null character (‘\0’ or NUL) at the end of a string?
A string is not a data type but a data structure. This means that its implementation is
logical not physical. The physical data structure is the array in which string is stored. Since
string, by definition, is a variable length structure, it is needed to identify the logical end of
the data within the physical structure.
18. What is an array? Give an example
 An array is a collection of data that holds fixed number of values of same type. Arrays
are widely used data type in ‘C’ language.
 It is a collection of elements of similar data type.
 It stores objects/variables of same data types in contiguous memory locations.
 Array elements can be accessed using index/subscript numbers.
 Array may be defined as a group of elements that share a common name.
 Example: int arr[10];
19. How to declare and initialize a 2D array?
Two-dimensional array is those type of array, which has finite number of rows and finite
number of columns. It has its element arranged in rectangular grid of rows and columns. The
declaration form of 2-dimensional array is:
Data_type Array_name [row size][column size];
Initialization of two dimensional array:
int marks[2][3]={10,20,30,40,50,60}
char nam[4][8] = { {“Abu”}, {“madhu”}, {“divya”}, {“raj”} }
int marks[2][3]={{90,87,78}, {68,62,71}};
20. Why is it necessary to give the size of an array in an array declaration?
When an array is declared, the compiler allocates a base address and reserves enough
space in the memory for all the elements of the array at compile time. Therefore, size must
be specified in array declaration inorder to allocate the required space.
21. What is meant by sorting? What are its types?
Sorting refers to ordering data in an increasing or decreasing fashion according to some
linear relationship among the data items. Sorting can be done on names, numbers and
records.
Types of sorting available in C:
Insertion sort, Merge Sort, Quick Sort, Radix Sort, Heap Sort, Selection sort, Bubble sort
22. Define searching.
Searching for data is one of the fundamental fields of computing. Search is an operation
in which a given list is searched for a particular value; the location of the searched element is
informed.
Various types of searching techniques in C are
Linear Search & Binary Search
23. State the rules for naming a variable in C language.
 A variable name can only have letters (both uppercase and lowercase letters), digits
and underscore.
 The first letter of a variable should be either a letter or an underscore.
 There is no rule on how long a variable name (identifier) can be.

4
 However, you may run into problems in some compilers if the variable name is
longer than 31 characters.
24.Write a C program to get a paragraph of text as input.
#include<stdio.h>
int main() {
char inputString[128], c;
int index = 0;
printf("Enter a multi line string( press ';' to end input)\n");
while((c = getchar()) != ';'){
inputString[index++] = c;
}
inputString[index] = '\0';
printf("Input String = %s", inputString);
return 0;
}
Output
Enter a multi line string(press ';' to end input)
Welcome
To C programming and Data Structures;
Input string
Welcome
To C programming and Data Structures;
25.Give the Length and Range of Primitive data types.
Keyword Size in
Data type Range Use
used bytes
Char char 1 -128 to 127 To store Characters
Int int 2 -32768 to 32767 To store integer numbers
Float float 4 -38 38 To store Floating point numbers
3.4*10 to 3.4*10
Double double 8 -308 308 To store big floating point numbers
1.7*10 to 1.7*10

26. What is function? List the purpose of function. Or What is the need for functions?
A function is a self-contained block of program statements that performs some specific
well-defined task. It is often defined as a section of a program performing a specific job.
Purposes:
 To enable code reusability.
 To improve readability of program.
 To avoid code redundancy
27. Write the syntax for including Function?
The syntax for including functions in program is
return_type function_name(datatype var1, datatype var2,…); //FUNCTION
DECLARATION
int main()
{ …..
variable_name = function_name(var1, var2, …); //FUNCTION CALL
return 0;
}
return_type function_name(datatype var1, datatype var2,…) //FUNCTION DEFINITION
5
{
statements
……
return(variable);
}
28. What are the components of a Function?
 Function Declaration
 Function Definition
 Function Call
29. Differentiate actual parameter and formal parameter.
Actual Parameter Formal Parameter
The Actual parameters are the values that The Formal Parameters are the variables
are passed to the function (i.e., in a defined by the function (i.e., in a function
function call) when it is invoked. header) that receives values when the
function is called.
The actual parameters are passed by the The formal parameters are in the called
calling function. In actual parameters, function. In formal parameters, the data types
there is no mentioning of data types. Only of the receiving values should be included.
the value is maintained.
30. State the difference between pass by reference and pass by value.

Pass by value Pass by reference


In pass by value, a copy of actual In pass by reference, the location (address) of
arguments is passed to formal arguments of actual arguments is passed to formal
the called function arguments of the called function.
any change made to the formal arguments Any changes made in the formal arguments
in the called function have no effect on the will also reflect in the actual arguments.
values of actual arguments in the calling Changes made inside the function are
function. reflected outside the function as well.
31. What is recursion? Give example.
A function that calls itself is called recursive function and the phenomenon is called
recursion.
Example: main()
{
main(); }
32. Give example on call by reference.
#include <stdio.h>
void swap(int *x, int *y); /* function declaration */
int main ()
{
int a = 100;
int b = 200;
printf("\nBefore swap, value of a : %d and value of b : %d", a,b );
swap(&a, &b); /* calling a function to swap the values.*/
printf("\nAfter swap, value of a : %d and value of b : %d ", a,b );
}
void swap(int *x, int *y) /* function definition to swap the values */
{
6
int temp;
temp = *x;
*x = *y;
*y = temp;
return;
}
33.Differentiate Row-Major and Column Major Representation of Arrays.
The difference is simply that 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.
34.Give the significance of function declaration.
A function is a group of statements that together perform a task. A function declaration tells
the compiler about a function's name, return type, and parameters. A function definition
provides the actual body of the function. Every C program has at least one function, which is
main().
35.What will be the output of the following program?
#include<stdio.h>
int main()
{
float x=0.1;
if(x==0.1)
printf(“IF”);
else if(x==0.1f)
printf(“ELSE IF”);
else
printf(“ELSE”);
}
Output:
ELSE IF
36. Differentiate between prefix and postfix increment operator.
Prefix Operator Postfix Operator
The increment operator ++ if used as prefix The increment operator ++ if used as postfix
on a variable, the value of variable gets on a variable, the value of variable is first
incremented by 1. returned and then gets incremented by 1
Eg: ++a; Eg: a++;

Part - B
1. Discuss about the various data types in “C”.
2. Explain in detail about “C” declarations and variables. (Jan 2011)
3. What are constants? Explain the various types of constants in C. (May 2015)
4. Explain about the various decision making statements in “C” language. (or) Write notes on
Branching Statements in C. (Jan 2014, May 2014, Jan 2016)
5. Explain various operators in c with example? (Nov/Dec 2014) (May 2015)
6. Explain briefly about the formatted and unformatted I/O function in C. (Jan 2012).
7. Explain the different looping statement with example?
(Jan 2014, Dec 2014, Jan 2016, May 2015)
8. Differentiate entry and exit checked conditional constructs with an example. (May 2014)
9. Write a C program to check whether the given number is palindrome or not
7
10. Write a C program to sum of digits of an integer. (Jan 2012, May 2014)
11. Write a C program for 1+2+3+4+5…n (Jan 2012)
12. Write a program to solve the Quadratic equation. (May 2015)
13. Write a program to find whether a number is prime or not. (May 2014)
14. Write a C program to reverse a String. (Jan 2014)
15. Write a program to print Fibonacci series for a given number. (Jan 2014)
16. Write a C program to find the Sum and difference of two matrices. (or) Write a C program
to add and subtract two matrices. (Jan 2014, May 2014, May 2015)
17. What is sorting? Write short notes on its types. Write a Program to Sort a set of numbers.
(or) Write a C program to arrange numbers in ascending order.
(May 2014, Dec 2014, May 2015, Nov 2017)
18. What is an array? Explain the characteristics and Classification of an array with examples.
19. Write a C program to find the largest and smallest element in an array.
20. Write a C program to search a given number in an array of elements.
(Nov/Dec 2014, May 2015)
21. Write a program using control structure if…..else that examines the value of an integer
variable called rating and print one of the following messages,
“Not recommended” – if the value of rating is less than 2
“Recommended” - if the value of rating lies between 2 and 4
“Highly recommended” - if the value of rating is above 4 (Nov/Dec 2022)
22. Define Recursive Function in C and Write a program to print the numbers from 1 to 5 using
recursive function. (Nov/Dec 2022)
23. Predict the output of the following Program and state the reason (Nov/Dec 2022)
int main()
{
int i=0;
while(i<=4)
{
printf(“%d”,i);
if(i>3)
goto inside_foo;
i++;
}
getchar();
return();
}
void foo()
{
inside_foo:
printf(“PP”);
}
24. Explain how multi-way selection “switch…case” statement implemented in c (Nov/Dec 2022)
25. Define Array and explain how it can be declared, initialized and accessed by specifying the
corresponding syntax. (Nov/Dec 2022)
26. Define Loop. Write the syntax of any two loop statements in C. (Nov/Dec 2022)

8
PART-C
1. Write a program for addition and multiplication of two matrices. (Jan 2016, Nov 2017)
2. Write a C program to find the Determinant of the resultant matrix. (Jan 2016)
3. Explain various String operations. Write a C Program to find length of a String without
using Library functions. (Nov/Dec 2014, May 2015)
4. Write a C program to find transpose of a matrix.
5. Write a C program to find sum of the elements in an array
6. Write a C program that implements binary search and linear search technique
7. Write a C program to count number of vowels, Consonants, Digits and spaces in a given
string.
(Nov 2017)
8. Write programs in ‘C’ to perform matrix addition and matrix multiplication. (Nov/Dec
2021)
9. Discuss pass by value and pass by reference techniques in C using suitable examples.
(Nov/Dec 2021)
10. Write a C program to exchange the values of two variables using functions. (May/June
2013)
11. Explain about the different parameter passing methods in functions with example
(Nov/Dec 2017)
12. Explain function with and without arguments with example for each. (Jan 2014)
13. Explain the pass by value and pass by reference with an example.
(May 2016) (April/May 2017) (Nov/Dec 2016) (April
2019)
14. Write a program to print Fibonacci series for a given number using recursion. (Jan 2016)
15. Write a c program using function to check if the given input number is palindrome or not.
(April/May 2015)
16. Write a C program to find the sum of the digits using recursive function. (April/May 2015)
17. What is recursion? Explain recursive function with suitable example. Write iterative and
recursive function to find power of a number. (Dec 2014)

You might also like