0% found this document useful (0 votes)
5 views31 pages

c Programming Assignment

The document discusses data types in C programming, explaining their importance in memory allocation and operations. It categorizes data types into primitive, user-defined, and derived types, detailing examples such as int, char, float, and structures. Additionally, it covers operators in C, classifying them into arithmetic, relational, logical, bitwise, assignment, and other operators, along with their functionalities.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views31 pages

c Programming Assignment

The document discusses data types in C programming, explaining their importance in memory allocation and operations. It categorizes data types into primitive, user-defined, and derived types, detailing examples such as int, char, float, and structures. Additionally, it covers operators in C, classifying them into arithmetic, relational, logical, bitwise, assignment, and other operators, along with their functionalities.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 31

Assignment

F.Y. – Sem-I
Sub: CS-02: Problem solving methodology &
Programming in C

 Q – 1: What is data type? Explain all data types available in C .


Ans: In the C programming language, a data type is a classification or category
that specifies which type of data a variable can hold, and it also defines the
operations that can be performed on that data.
Data types are essential because they determine how much memory is
allocated for a variable, how the data is stored in memory, and what operations
can be applied to the data.
We know that computers store all the data in the form of binary numbers,
and it assigns memory to each of them. Now suppose you want to make a
program to store your name, age and phone number.
Without mentioning the data types, your computer would not be able to
distinguish between your name, age and phone number and will treat them
equally by assigning the same memory and keeping them in the same set of
variables.
The age consists of the utmost 2 to 3 digits and the phone number consists
of at least 10 digits, but computers will assign the same memory to both of them
that will lead to a lot of memory wastage.
To deal with such scenarios, we assign data types to each variable to prevent
any confusion or memory wastage.
C provides several built-in data types, and you can also create custom data
types using structures and unions.
Here are some of the common built-in data types in C:

Types Description

Primitive data types are the most basic data types that are
Primitive Data
Types used for representing simple values such as integers, float,
characters, etc.

User Defined
Data Types The user-defined data types are defined by the user himself.

Derived Types
The data types that are derived from the primitive or built-
in data types are referred to as Derived Data Types.

Types Data Types

Basic Data Type int, char, float, double

Derived Data Type array, pointer, structure, union

Enumeration Data Type Enum

Void Data Type Void

Type Size (bytes) Format Code


Int at least 2, usually 4 %d, %i
Char 1 %c
Float 4 %f
Double 8 %lf
short int 2 usually %hd
unsigned int at least 2, usually 4 %u
long int at least 4, usually 8 %ld, %li
signed char 1 %c
unsigned char 1 %c
long double at least 10, usually 12 or 16 %Lf
 Primitive / Basic (Primary) data types
These are the most basic data types and all the other data typed are derived or
made from them only. It contains integer, floating point and char.
Four main types of primary/basic data types are:
1. Integer
2. Float
3. Char
4. Void

1. CHAR DATA TYPE IN C

It is used to store a single character and requires 1 byte. A character could be


any alphabet, number or special character written inside a pair of single
inverted commas, eg ‘1’, ‘a’, ‘#’ etc.
Since it requires 1 Byte, which is 8 bits, the number of characters in C
language is 256(2^8). Memory space differs with use of prefixes
#include <stdio.h>
void main() {
char c;
c = 'a' ;
printf("%c",c);
}

2. INT DATA TYPE IN C


It is used to store integer values and requires memory according to the value
of the integer we want to store.
The size of int is compiler dependent. For example, 32-bit compilers have int
as 4 bytes but 64 bits compilers (which we are using now) have int as 8 bytes.
And since the size varies the range of values integers can store also varies
from compiler to compiler.
For 2 bytes, it’s 0 to 65,535 for an unsigned integer.
For 4 bytes, it’s 0 to 4,29,49,67,296 for an unsigned integer.
#include <stdio.h>
void main() {
int i;
i = 10;

printf("%d",i);
}

3. FLOAT
Floating point numbers are used to store decimal numbers. The range of
values it can store also varies from compiler to compiler.
For 32-bit and 64-bit compilers, it is the same as 4 bytes. That is 2^(4*8)
length of value, which is 4,29,49,67,296 i.e. 0 to 4,29,49,67,296 numbers can
be represented using float.
#include <stdio.h>
void main() {
float f;
f = 1.20 ;
printf("%f",f);
}

4. VOID

It is a special type known as empty data type that is used to state that a given
variable does not have any type. This is mainly used in defining functions
where we do not want to return any value.
 Secondary data types:
Secondary data types are formed by combining two or more primary data
types in C.
They are mainly of two types:
1. USER-DEFINED DATA TYPES
2. DERIVED DATA TYPE

1. USER-DEFINED DATA TYPES IN C

These data types are defined by the user as per their convenience. If a user
feels a need of having a data type which is not predefined in C library, then
they make their own.
 STRUCTURE

Structure is a user-defined data type in C, where we can store values of


multiple data types.
For example, if you want to store details of students of a college, where each
student will be having a name, roll no and marks. But managing the data of
one student together (string, int and float variable) for a student is not possible
with any of the data types we have discussed so far. Now for this we use
another data type known as Structure.
Let's say I create a structure of students with the fields such as name, roll no
and marks. Now for each student I can create a variable of structure which
will store data of that particular student. And I can access it whenever I want.
 UNION

Union is quite similar to structure as it is also used to store values of multiple


data types.
 3. ENUM

Enum is a user-defined data type, which is used to make a program more


readable and understandable. It is used to assign text values to integer values.
It basically uses an indexing method and assigns text values to the concerned
index value.
In the below given figure 0 will be assigned to Jan, 1 to Feb, 3 to Apr and so
on.
2. DERIVED DATA TYPES

Derived data types are data types which are formed by combining one or more
primitive data types or basic data types in C. For example, there might be
some cases where primitive data types are not sufficient for us. Like if we
want to store a phone number we can use an integer but what if we want to
store phone numbers of all the students in a college. Making variables for each
of them is not the optimal way.
To deal with such situations optimally, C has some derived data types, which
we can use as per our convenience.
1. ARRAY
2. POINTER

 Q – 2: What is Operator? Explain all types of operators of C.


Ans: C Operators are symbols that represent operations to be performed on one
or more operands. C provides a wide range of operators, which can be classified
into different categories based on their functionality. Operators are used for
performing operations on variables and values.

Operators can be defined as the symbols that help us to perform specific


mathematical, relational, bitwise, conditional, or logical computations on
operands. In other words, we can say that an operator operates the operands.
For example, ‘+’ is an operator used for addition, as shown below:
c = a + b;
Here, ‘+’ is the operator known as the addition operator, and ‘a’ and ‘b’ are
operands. The addition operator tells the compiler to add both of the operands
‘a’ and ‘b’. The functionality of the C programming language is incomplete
without the use of operators.
Types of Operators in C
C has many built-in operators and can be classified into 6 types:

1. Arithmetic Operators
2. Relational Operators
3. Logical Operators
4. Bitwise Operators
5. Assignment Operators
6. Other Operators

1. Arithmetic Operations in C
These operators are used to perform arithmetic/mathematical
operations on operands. Examples: (+, -, *, /, %,++,–). Arithmetic
operators are of two types:
a) Unary Operators:
Operators that operate or work with a single operand are unary
operators. For example: Increment(++) and Decrement(–) Operators
int val = 5;
cout<<++val; // 6
b) Binary Operators:
Operators that operate or work with two operands are binary
operators. For example: Addition(+), Subtraction(-), multiplication(*),
Division(/) operators
int a = 7;
int b = 2;
cout<<a+b; // 9

2. Relational Operators in C
These are used for the comparison of the values of two operands. For
example, checking if one operand is equal to the other operand or not,
whether an operand is greater than the other operand or not, etc.
Some of the relational operators are (==, >= , <= )
int a = 3;
int b = 5;
cout<<(a < b);
// operator to check if a is smaller than b
3. Logical Operator in C
Logical Operators are used to combining two or more
conditions/constraints or to complement the evaluation of the
original condition in consideration. The result of the operation of a
logical operator is a Boolean value either true or false.
For example, the logical AND represented as the ‘&&’ operator in
C returns true when both the conditions under consideration are
satisfied. Otherwise, it returns false. Therefore, a && b returns true
when both a and b are true (i.e. non-zero)
4. Bitwise Operators in C
The Bitwise operators are used to perform bit-level operations on the
operands. The operators are first converted to bit-level and then the
calculation is performed on the operands. Mathematical operations
such as addition, subtraction, multiplication, etc. can be performed at
the bit level for faster processing. For example, the bitwise
AND operator represented as ‘&’ in C takes two numbers as operands
and does AND on every bit of two numbers. The result of AND is 1
only if both bits are 1(True).
int a = 5, b = 9; // a = 5(00000101), b = 9(00001001)
cout << (a ^ b); // 00001100
cout <<(~a); // 11111010
5. Assignment Operators in C
Assignment operators are used to assign value to a variable. The left
side operand of the assignment operator is a variable and the right
side operand of the assignment operator is a value. The value on the
right side must be of the same data type as the variable on the left side
otherwise the compiler will raise an error.
Different types of assignment operators are shown below:
a) “=”
This is the simplest assignment operator. This operator is used to
assign the value on the right to the variable on the left.
Example:
a = 10;
b = 20;
ch = 'y';
b) “+=”
This operator is the combination of the ‘+’ and ‘=’ operators. This
operator first adds the current value of the variable on left to the value
on the right and then assigns the result to the variable on the left.
Example:
(a += b) can be written as (a = a + b)
If initially value stored in a is 5. Then (a += 6) = 11.
c) “-=”
This operator is a combination of ‘-‘ and ‘=’ operators. This operator
first subtracts the value on the right from the current value of the
variable on left and then assigns the result to the variable on the left.
Example:
(a -= b) can be written as (a = a - b)
If initially value stored in a is 8. Then (a -= 6) = 2.
d) “*=”
This operator is a combination of the ‘*’ and ‘=’ operators. This
operator first multiplies the current value of the variable on left to the
value on the right and then assigns the result to the variable on the
left.
Example:
(a *= b) can be written as (a = a * b)
If initially, the value stored in a is 5. Then (a *= 6) = 30.
e) “/=”
This operator is a combination of the ‘/’ and ‘=’ operators. This
operator first divides the current value of the variable on left by the
value on the right and then assigns the result to the variable on the
left.
Example:
(a /= b) can be written as (a = a / b)
If initially, the value stored in a is 6. Then (a /= 2) = 3.
6. Other Operators
Apart from the above operators, there are some other operators
available in C used to perform some specific tasks. Some of them are
discussed here:
i. sizeof operator
 sizeof is much used in the C programming language.

 It is a compile-time unary operator which can be used to compute

the size of its operand.


 The result of sizeof is of the unsigned integral type which is usually

denoted by size_t.
 Basically, the sizeof the operator is used to compute the size of the

variable.
ii. Comma Operator
 The comma operator (represented by the token) is a binary operator

that evaluates its first operand and discards the result, it then
evaluates the second operand and returns this value (and type).
 The comma operator has the lowest precedence of any C operator.

 Comma acts as both operator and separator.

iii. Conditional Operator


 The conditional operator is of the form Expression1? Expression2:

Expression3
 Here, Expression1 is the condition to be evaluated. If the

condition(Expression1) is True then we will execute and return the


result of Expression2 otherwise if the condition(Expression1)
is false then we will execute and return the result of Expression3.
 We may replace the use of if..else statements with conditional

operators.
iv. dot (.) and arrow (->) Operators
 Member operators are used to referencing individual members of

classes, structures, and unions.


 The dot operator is applied to the actual object.

 The arrow operator is used with a pointer to an object.


v. Cast Operator
 Casting operators convert one data type to another. For example,

int(2.2000) would return 2.


 A cast is a special operator that forces one data type to be converted

into another.
 The most general cast supported by most of the C compilers is as

follows − [ (type) expression ].


vi. &,* Operator
 Pointer operator & returns the address of a variable. For example

&a; will give the actual address of the variable.


 The pointer operator * is a pointer to a variable. For example *var;

will pointer to a variable var.

 Q – 3: Explain Selective (Conditional) control structure of C.


Ans:
Control Structures are just a way to specify flow of control in programs. Any
algorithm or program can be clearer and understood if they use self-contained
modules called as logic or control structures. It basically analyses and chooses
in which direction a program flows based on certain parameters or conditions.

The conditional statements (also known as decision control structures) such


as if, if else, switch, etc. are used for decision-making purposes in C programs.
They are also known as 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.

Need of Conditional Statements


There come situations in real life when we need to make some decisions and
based on these decisions, we decide what we should do next. Similar
situations arise in programming also where we need to make some decisions
and based on these decisions we will execute the next block of code. For
example, in C if x occurs then execute y else execute z. There can also be
multiple conditions like in C if x occurs then execute p, else if condition y
occurs execute q, else execute r. This condition of C else-if is one of the many
ways of importing multiple conditions.

There are five conditional / selective control structures are as follows:

1. if Statement
2. if-else Statement
3. Nested if Statement
4. if-else-if Ladder
5. switch Statement

if statement ( Single Alternative )


This structure has the form:
if (condition) then:
[Module A]
[End of If structure]

if statement is the most simple decision making statement. It is used


to decide whether a certain statement or block of statements will be
executed or not based on a certain type of condition.

Syntax:
if(condition)
{
// Statements to execute if
// condition is true
}
#include <stdio.h>
int main()
{
int i = 10;
if (i < 15) {
printf("10 is less than 15 \n");
}
printf("I am Not in if");
}

 if-else Statement (Double Alternative)

This structure has the form:


If (Condition), then:
[Module A]
Else:
[Module B]
[End if structure]

The if statement alone tells us that if a condition is true it will execute


a block of statements and if the condition is false it won’t. But what if
we want to do something else if the condition is false. Here comes the
C/C++ else statement. We can use the else statement with if
statement to execute a block of code when the condition is false.
Syntax:
if (condition)
{
// Executes if condition is true
}
else
{
//Executes if condition is false
}
Example:
#include <stdio.h>
int main()
{
int i = 20;
if (i < 15) {
printf("i is smaller than 15");
}
else {
printf("i is greater than 15");
}
return 0;
}

 if-else-if ladder (Multiple Alternatives)


if-else-if ladder helps user decide from among multiple options. The
C/C++ if statements are executed from the top down. As soon as one
of the conditions controlling the if is true, the statement associated
with that if is executed, and the rest of the C else-if ladder is bypassed.
If none of the conditions is true, then the final else statement will be
executed.
Syntax:
if (condition)
statement 1;
else if (condition)
statement 2;
.
.
else
statement;
Example:
#include <stdio.h>
int main()
{
int i = 20;
if (i == 10)
printf("i is 10");
else if (i == 15)
printf("i is 15");
else if (i == 20)
printf("i is 20");
else
printf("i is not present");
return 0;
}

 Nested if Statement (Nested Alternatives)

A nested if in C is an if statement that is the target of another if


statement. Nested if statements mean an if statement inside another if
statement. Yes, both C and C++ allow us to nested if statements within
if statements, i.e, we can place an if statement inside another if
statement.
Syntax of Nested if-else

if (condition1)
{
// Executes when condition1 is true
if (condition2)
{
// Executes when condition2 is true
}
else
{
// Executes when condition2 is false
}

Flowchart of Nested if-else


Example:
#include <stdio.h>
int main()
{
int i = 10;
if (i == 10) {
if (i < 15)
printf("i is smaller than 15\n");
if (i < 12)
printf("i is smaller than 12 too\n");
else
printf("i is greater than 15");
}
return 0;
}
 Switch Statement
The switch case statement is an alternative to the if else if ladder that can be
used to execute the conditional code based on the value of the variable
specified in the switch statement. The switch block consists of cases to be
executed based on the value of the
switch variable.

Syntax of switch:
switch (expression) {
case value1:
statements;
case value2:
statements;
....
....
....
default:
statements;
}
Example:
#include <stdio.h>
int main()
{
int var = 2;
switch (var) {
case 1:
printf("Case 1 is executed");
break;
case 2:
printf("Case 2 is executed");
break;
default:
printf("Default Case is executed");
break;
}
return 0;
}
 Q – 4: Explain Looping control structure of C.
Ans: 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.
There are mainly two types of loops in C Programming:
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.

Entry Control Loop:


 While loop:
The while Loop is an entry-controlled loop in C programming language.
This loop can be used to iterate a part of code while the given condition
remains true.
Syntax
The while loop syntax is as follows:
while (test expression)
{
// body consisting of multiple statements
}
#include <stdio.h>
int main()
{
int i = 0;
while (i < 5) {
printf("Hello Creative\n");
i++;
}
return 0;
}

 for Loop
The for loop in C Language provides a functionality/feature to repeat a set
of statements a defined number of times. The for loop is in itself a form of
an entry-controlled loop.
Unlike the while loop and do…while loop, the for loop contains the
initialization, condition, and updating statements as part of its syntax. It is
mainly used to traverse arrays, vectors, and other data structures.
Syntax of for Loop
for(initialization; check/test expression; updation)
{
// body consisting of
multiple statements
}
#include <stdio.h>
int main()
{
int i = 0;
for (i=0; i < 5 ; i++) {
printf("Hello Creative\n");
}
return 0;
}

Exit Control Loop:


 do while loop:
The do…while in C is a loop statement used to repeat some part
of the code till the given condition is fulfilled. It is a form of
an exit-controlled or post-tested loop where the test condition is
checked after executing the body of
the loop. Due to this, the statements
in the do…while loop will always be
executed at least once no matter what
the condition is.
 Syntax:
do {

// body of do-while loop

} while (condition);
#include <stdio.h>
int main()
{
int i = 0;
do
{
printf("Hello Creative\n");
}while(i<5);
return 0;
}

 Q – 5: What is array? Explain all types of array available in C.


Ans: 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.

In C, we have to declare the array like any other variable before using it. We can
declare an array by specifying its name, the type of its elements, and the size of its
dimensions. When we declare an array in C, the compiler allocates the memory
block of the specified size to the array name.
data_type array_name [size];
or
data_type array_name [size1] [size2]...[sizeN];

C Array Initialization
Initialization in C is the process to assign some initial value to the variable. When
the array is declared or allocated memory, the elements of the array contain some
garbage value. So, we need to initialize the array to some meaningful value. There
are multiple ways in which we can initialize an array in C.

1. Array Initialization with Declaration:


In this method, we initialize the array along with its declaration. We use an
initializer list to initialize multiple elements of the array. An initializer list is
the list of values enclosed within braces { } separated b a comma.
Syntax:
data_type array_name [size] = {value1, value2, ... valueN};

Types of Array in C
There are two types of arrays based on the number of dimensions it has. They are as
follows:
1. One Dimensional Arrays (1D Array)
2. Multidimensional Arrays
1. One Dimensional Array in C
The One-dimensional arrays, also known as 1-D arrays in C are those arrays that have only
one dimension.
Syntax of 1D Array in C
array_name [size];
Example:
#include <stdio.h>
int main()
{
int arr[5];
for (int i = 0; i < 5; i++) {
arr[i] = i * i - 2 * i + 1;
}
printf("Elements of Array: ");
for (int i = 0; i < 5; i++) {
printf("%d ", arr[i]);
}
return 0;
}

2. Multidimensional Array in C
Multi-dimensional Arrays in C are those arrays that have more than one
dimension. Some of the popular multidimensional arrays are 2D arrays and 3D
arrays. We can declare arrays with more dimensions than 3d arrays but they
are avoided as they get very complex and occupy a large amount of space.
A. Two-Dimensional Array in C
A Two-Dimensional array or 2D array in C is an array that has exactly two
dimensions. They can be visualized in the form of rows and columns
organized in a two-dimensional plane.
Syntax of 2D Array in C
array_name[size1] [size2];

Here,
 size1: Size of the first dimension.
 size2: Size of the second dimension.

#include <stdio.h>
int main()
{
int arr[2][3] = { 10, 20, 30, 40, 50, 60 };
printf("2D Array:\n");
for (int i = 0; i < 2; i++) {
for (int j = 0; j < 3; j++) {
printf("%d ",arr[i][j]);
}
printf("\n");
}
return 0;
}

3. Multi (Three)-Dimensional Array


Another popular form of a multi-dimensional array is Three
Dimensional Array or 3D Array. A 3D array has exactly three
dimensions. It can be visualized as a collection of 2D arrays stacked
on top of each other to create the third dimension.
Syntax of 3D Array
array_name [size1] [size2] [size3];
// C Program to illustrate the 3d array
#include <stdio.h>

int main()
{
int arr[2][2][2] = { 10, 20, 30, 40, 50, 60 };
for (int i = 0; i < 2; i++) {
for (int j = 0; j < 2; j++) {
for (int k = 0; k < 2; k++) {
printf("%d ", arr[i][j][k]);
}
printf("\n");
}
printf("\n \n");
}
return 0;
}
 Q – 6: Explain UDF with all its types.
A function is self-contained block of code that performs a particular
task functions can be classified into two categories namely library
function and user defined function. The main difference between two
these categories is that library function are need not to be written by us
when user defined functions has to be developed by users.
Types of Functions

There are two types of functions in C programming:

Library Functions: are the functions which are declared in the C


header files such as scanf(), printf(), gets(), puts(), ceil(), floor() etc.

User-defined functions: are the functions which are created by


the C programmer, so that he/she can use it many times. It
reduces the complexity of a big program and optimizes the code.
Features of User Defined Function:

 In c, we can divide a large program into the basic building blocks


known as function.
 The function contains the set of programming statements enclosed
by {}.
 A function can be called multiple times to provide reusability and
modularity to the C program.
 In other words, we can say that the collection of functions creates a
program.
 Function which are defined by USER.
 Function which are define as per user requirement are known as
User Defined Function.
 UDF are also used to stop repetition and duplication of codes.
 While working with user defined function, first of all we
have to declare the function and its return type.
 If your function will not return any value then declare function with
VOID type.
 If your data will be returned in the form of integer then we
have to declare UDF with int data type.
 If your data will be returned in the form of float then we have to
declare UDF float data type.

Advantage of functions in C :
 The main advantages of using UDF is that it can be called & used
whenever and wherever
 required in the program.
 It can be used t to implement or facilitates top-down modular
programming approach, by
 which the logic of program can be divided into functions.
 By using functions, we can avoid rewriting same logic/code again
and again in a program.
 We can call C functions any number of times in a program and from
any place in a program.
 We can track a large C program easily when it is divided into
multiple functions.
 Reusability is the main achievement of C functions.
 The length of source program can be reduce which save both
time and space. Function are made for reusability. In
case of large program with thousands of code lines,
debugging and editing become easier if you use function.

How to define UDF ?


Syntax:
ReturnType FunctionName(argument list);
Purpose:
To declare UDF with required return type we can use above syntax.

Example :
void starline( ); int sum(int,int);
float interest(float,float,float);

Types of User Defined Functions :


The function can categories in four types. As per its argument
and return type.
[1] No Argument and No Return Value.
[2] With Argument and No Return Value.
[3] With argument and With Return Value.
[4] No Argument and With Return Value.

1) No Argument and No Return Value :

 When function doesn’t have any argument and doesn’t have any return value
at that time it is called as Function with no Argument and no Return Value.
 Means the called function will not receive any argument form the calling
function and it will not return any value to calling function.
 We can use any UDF at any number of times.

 Ex :
void get()
{
Printf(“Hello this is testing function”);
}
Void main()
{
get();
}

2) With Argument and No Return Value :

 When function have some argument to send called function and have
not any return value at that time it is called as Function with
Argument and No Return Value.
 Means the called function will receive some argument form the
calling function but it will no return value to calling function.
Ex :

void get(int a)
{
Printf(“A=%d”,a);
}
void main()
{
get(10);
}

3) With argument and With Return Value :


 When function have some argument to send called function and have
return value at that time it is called as Function with Argument and
Return Value.
 Means the called function will receive some argument form the
calling function and it will return value to calling function.
Ex :
int get(int a,int b)
{
int c;
c=a+b;
return c;
}
void main()
{
int a=10,b=20,c;
C=get();
printf(“\nSum=%d”,c);
}
4) No Argument and With Return Value :
 When function doesn’t have any argument and have any return value at that
time
it is called as Function with no Argument and Return Value.
 Means the called function will not receive any argument form the
calling function but it will return value to calling function.
Ex:
int get()
{
int a=5,b=10,c; C=a+b;
return c;
}
void main()
{
int sum; Sum=get();
printf(“\nsum=%d”,sum); }

You might also like