C Lamnguage Programing
C Lamnguage Programing
MANIPALL UNIVERSITY
JAIPUR
INTERNAL ASSIGNMENT
set --1
1. Procedural Language
2. Fast and Efficient
3. Modularity
4. Statically Type
5. General-Purpose Language
6. Rich set of built-in Operators
7. Libraries with Rich Functions
8. Middle-Level Language
9. Portability
1. Procedural Language
In a procedural language like C step by step, predefined instructions are carried out. C
program may contain more than one function to perform a particular task. New people
to programming will think that this is the only way a particular programming
language works. There are other programming paradigms as well in the programming
world. Most of the commonly used paradigm is an object-oriented programming
language.
Newer languages like Java, python offer more features than c programming
language but due to additional processing in these languages, their performance rate
gets down effectively. C programming language as the middle-level language
provides programmers access to direct manipulation with the computer hardware but
higher-level languages do not allow this. That’s one of the reasons C language is
considered the first choice to start learning programming languages. It’s fast because
statically typed languages are faster than dynamically typed languages.
3. Modularity
The concept of storing C programming language code in the form of libraries for
further future uses is known as modularity. This programming language can do very
little on its own most of its power is held by its libraries. C language has its
own library to solve common problems.
4. Statically Type
5. General-Purpose Language
It is a diversified language with a rich set of built-in operators which are used in
writing complex or simplified C programs.
Robust libraries and functions in C help even a beginner coder to code with ease.
8. Middle-Level Language
9. Portability
C language is lavishly portable as programs that are written in C language can run and
compile on any system with either no or small changes.
ANS.
There are several types of flow control statements commonly used in C programming:
1.
2.
3.
4.
5.
6.
Flow control statements provide a way to make programs more dynamic and
adaptable by allowing different paths of code execution based on specific conditions
or requirement.
3.Define a function. List and example the categories of user defined functions.
ANS. A user-defined function can be a scalar function, which returns a single value
each time it is called; an aggregate function, which is passed a set of like values and
returns a single value for the set; a row function, which returns one row; or a table
function, which returns a table.
No arguments and no return value - These functions are usually used to perform tasks on
global variables or to display information.
No arguments and with return value - These functions are usually used to perform various
operations and return the results.
With arguments and no return value - These functions are usually used to display the results
of the operations performed inside the function.
With arguments and with return value - These functions are used to perform specific
operations on the arguments and return the result.
SET ---2
4. Define an array. How to initialize a one dimensional array? Explain with suitable
example.
ANS. An array is defined as an ordered set of similar data items. All the data items of
an array are stored in consecutive memory locations in RAM. The elements of an
array are of same data type and each item can be accessed using the same name.
(i) Initializing all specified memory locations:- Arrays can be initialized at the time of
declaration when their initial values are known in advance. Array elements can be
initialized with data items of type int, char etc. Ex:- int a[5]={10,15,1,3,20}; During
compilation, 5 contiguous memory locations are reserved by the compiler for the
variable a and all these locations are initialized . Initialization of int Arrays Ex:- int
a[3]={9,2,4,5,6}; //error: no. of initial vales are more than the size of array.
In this declaration, even though we have not specified exact number of elements to be
used in array b, the array size will be set of the total number of initial values specified.
So, the array size will be set to 8 automatically. The array b is initialized .
Initialization without size Ex:- int ch[]={1,0,3,5} // array size is 4.
(iv) Array initialization with a string: -Consider the declaration with string
initialization. Ex:- char b[]="COMPUTER"; The array b is initialized . Array
Initialized with a String Even though the string "COMPUTER" contains 8 characters,
because it is a string, it always ends with null character. So, the array size is 9 bytes
(i.e., string length 1 byte for null character). Ex:- char b[9]="COMPUTER"; // correct
char b[8]="COMPUTER";. Run Time Initialization An array can be explicitly
initialized at run time. This approach is usually applied for initializing large arrays.
Ex:- scanf can be used to initialize an array. int x[3]; scanf(“%d%d
%d”,&x[0],&x[1],&x[2]);
6
The above statements will initialize array elements with the values entered through
the key board. (Or) for(i=0;i<100;i=i+1) { if(i<50) sum[i]=0.0; else sum[i]=1.0; } The
first 50 elements of the array sum are initialized to 0 while the remaining 50 are
initialized to 1.0 .
5. (a) Define structure and write the general syntax for declaring and accessing
members.
ANS. Syntax to Define a Structure in Cdata_Type: The data type indicates the
type of the data members of the structure. A structure can have data members of
different data types. member_name. This is the name of the data member of the
structure. Any number of data members can be defined inside a structure.
This way of creating structure variables is preferred when multiple variables are
required to be declared. The structure variables are declared outside the structure.
Syntax
struct structName
// structure definition
Data_type1 member_name1;
Data_type2 member_name2;
Data_type2 member_name2;
};
Example
struct bookStore
// structure definition
char storeName
7
int totalBooks;
char storeLicense[20];
};
int main()
When the structure variables are declared in the main() function, the keyword struct
followed by the structure name has to be specified before declaring the variables. In
the above example, storeA and storeB are the variables .
8
Keyword A user can deploy the keyword struct to A user can deploy the keyword union to
define a Structure. define a Union.
Accessing Members A user can access individual members at a A user can access only one member at a
given time. given time.
{ {
. .
. .
Size A Structure does not have a shared A Union does not have a separate
location for all of its members. It location for every member in it. It
makes the size of a Structure to be makes its size equal to the size of
greater than or equal to the sum of the largest member among all the data
9
Value Altering Altering the values of a single When you alter the values of a single
member does not affect the other member, it affects the values of
members of a Structure. other members.
Initialization In the case of a Structure, a user In the case of a Union, a user can
can initialize multiple members at only initiate the first member at a
the same time. time.
1 When the allocation of memory performs When the memory allocation is done at the
at the compile time, then it is known execution or run time, then it is called
as static memory. dynamic memory allocation.
2 The memory is allocated at the compile The memory is allocated at the runtime.
time.
6 Static memory allocation allots memory Dynamic memory allocation allots memory from
from the stack. the heap.
7 Once the memory is allotted, it will Here, the memory can be alloted at any time
remain from the beginning to end of the in the program.
program.
.
11
i
THE END