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

UNIT I C PROGRAMMING FUNDAMENTAL2

The document covers fundamental concepts of C programming, including programming paradigms, assignment statements, keywords, variables, and operators. It explains the compilation process, storage classes, and the use of functions, along with examples of recursion and array initialization. Additionally, it discusses decision-making statements and provides sample programs for various tasks such as calculating string length and generating Fibonacci series.

Uploaded by

rebecca
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)
2 views

UNIT I C PROGRAMMING FUNDAMENTAL2

The document covers fundamental concepts of C programming, including programming paradigms, assignment statements, keywords, variables, and operators. It explains the compilation process, storage classes, and the use of functions, along with examples of recursion and array initialization. Additionally, it discusses decision-making statements and provides sample programs for various tasks such as calculating string length and generating Fibonacci series.

Uploaded by

rebecca
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/ 6

UNIT I C PROGRAMMING FUNDAMENTALS

PART A
1. Define programming paradigm.
Programming paradigm is a style or way of programming. The are procedural,
functional,
object-oriented, logic programming.
Some of the programming languages are
 Fortran
 Cobol
 Basic
 Pascal
C

2. Give two examples for assignment statements.


Syntax for assignment : variable = expression / value ; Example : x=100;
y= a+b;

3. What are keywords? Give an example


 Keywords are reserved words, they have standard and predefined meaning.
 Keywords cannot be used as normal identifiers.
 Example : auto, break, char, continue, else, if, switch, struct, union.

4. What do you mean by variables in ‘C’ ?


A variable is an identifier that is used to represent some specified type of
information.
Syntax : data_type variable_name; Example :int marks;

5. Identify the use of ternary or conditional operator.


 ?: is known as conditional operator.It evaluates the first expression if the condition
is true
otherwise the second expression is evaluated.
 Syntax : condition ? exp1 : exp2 ;

6. What is a compilation process?


Compiler converts source code into executable code. It includes
 Pre-processor
 Compilation
 Assembly
 Linking

7. Differentiate between an expression and a statement in C.


8. What is the output of the programs given below?
#include <stdio.h> main( )
{
int a = 20, b = 10, c = 15, d = 5; int e;
e = (a + b) * c / d;
printf("Value of (a + b) * c / d is : %d\n", e );
}
OUTPUT :
Value of (a + b) * c / d is : 90

9. Classify the different types of storage classes .


There are mainly four types of storage classes. They are
Automatic (auto)
Static
External (ext)

10. Discover the meaning of C pre-processor


The reprocessor contains any operations in the processing language, it will be
transformed
first.
1. The preprocessing language consists of
Inclusion of header file
Macro expansion
Conditional compilation
Line control
Diagnostics
11. Invent the difference between ++a and a++.
++a is known as pre increment where the value is incremented by one and then the
operation
is done.
a++ is known as post increment where the operation is done first and then the
value is
incremented by one.

12. Differentiate switch( ) and nested-if statement


13. Summarize the various types of C operators.
Arithmatic operators
Relational operators
Logical operators
Increment or decrement operators
Conditional or Ternary operators

Bitwise operators
Special operators (sizeof, & and * , . and -->)

14. Recommend the suitable example for infinite loop using while.
#include<stdio.h> void main()
{
int i = 1;
while( i<10 )
{
printf(“%d\n”,i);
}
getch( );
}
Here we are not updating the value of i. so after each iteration value of i remains
same. As
a result, the condition (i<10) will always true so it will print infinity loop.

15. How to create a two dimensional array?


Two dimensional arrays are stored in a row-column matrix, where the left index
indicates the
row and right matrix indicates the column.
Syntax : data_type array_name[row_size][column_size]; Example : int mat[3][3];

16..What are the different ways of initializing array?


Values can be assigned to an array by normal declaration otherwise they hold
garbage values.
Arrays can be initialized in following two ways :
i. At compile time
ii. At Run time
17..Define string.
String is a sequence / array of characters enclosed with double quotes.
Null character (‘\0’) is used to mark the end of the string
Example : char word= “computer”

18. Define Multi-dimensional array.


Multi-dimensioned arrays have two or more index values which specify the
element in the
array.
Declaration:
int m1[10][10];
static int m2[2][2] = { {0,1}, {2,3} };

19.Write a C program to find the length of given string.


PROGRAM
#include <stdio.h> int main()
{
char s[1000], i;
printf("Enter a string: ");
scanf("%s", s);
for(i = 0; s[i] != '\0'; ++i)
printf("Length of string: %d", i);
return 0;
}
OUTPUT
Enter a string: Programming in C Length of string:16

20. What is a function?


Function is a set of instructions
Self contained block
Performs a specific task
Used to avoid redundancy of code
21.What is the need for functions?
To reduce the complexity of large programs
To increase the readability
To achieve reusability
To avoid redundancy of code
To save Memory

22.Compare actual parameter & formal argument


Actual argument: Specified in the function call statement. Used to supply the input
values to the
function either by copy or reference
Formal argument: Specified in the function definition statement. It takes either copy
or address
of the actual arguments
23. What is a function prototype?
Function prototype is a function declaration statement. Syntax : return_type
function_name(parameters_list)
Example: int factorial(int);

24.Differentiate call by value and call by reference.


Call by value: The values of the variables are passed by the calling function to the
called function.
Call by reference: The addresses of the variables are passed by the calling function
to the called function.

25. Write the advantages and disadvantages of recursion.


Recursion makes program elegant and cleaner. All algorithms can be defined
recursively which makes it easier to visualize and prove.If the speed of the program
is vital then, you should avoid using recursion.
Recursions use more memory and are generally slow. Instead, you can use loop.

26.What is meant by Recursive function?


If a function calls itself again and again, then that function is called Recursive
function.

Example:
void recursion()
{
recursion(); /* function calls itself */
}
int main()
{
recursion();

27.What are the steps in writing a function in a program?


Function Declaration (Prototype declaration):
Every user-defined functions has to be declared before the main().
Function Callings:
The user-defined functions can be called inside any functions like main(),
userdefined function, etc.
Function Definition:
The function definition block is used to define the user-defined functions with
statements.

PART B
1. List the different data types available in C.
2. Explain the different types of operators available in C.
3. Explain about various decision making statements available in C with illustrative
programs
4. Write a C program to print the Fibonacci series of a given number.
5. Explain in detail about functions & Function prototypes?
PART C
1. Explain in detail about Recursion with its example
2. Tower of Hanoi with sample program?
3. What is an array? Discuss how to initialize a one dimensional and two
dimensional arrays

You might also like