0% found this document useful (0 votes)
32 views12 pages

C Lamnguage Programing

Uploaded by

guptaanish978
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)
32 views12 pages

C Lamnguage Programing

Uploaded by

guptaanish978
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/ 12

1

MANIPALL UNIVERSITY

JAIPUR

INTERNAL ASSIGNMENT

SESSION AUGUSTT 2023


PROGRAM BCA
SMESTER 1
NAME ANISH GUPTA
ROLL NUMBER 2314520442
COURSE CODE & NAME DCA11002-PROGRAMING IN C
CREDITS 4
NUMBER OF ASIGNMENTS & 02 & 30 Marks each
MARKS

set --1

1. Describe various feature of C programming language. .

ANS C is a procedural programming language. It was initially


developed by Dennis in the year 1972. It was mainly developed as a
2

system programming language to write an operating system.The main


features of C language include low-level access to memory, a simple
set of keywords, and a clean style, these features make C language
suitable for system programming like an operating system or compiler
development.

Here are some important feature of C programing.

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.

2. Fast and Efficient

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

C programming language is a statically typed language. Meaning the type of variable


is checked at the time of compilation but not at run time. This means each time a
programmer types a program they have to mention the type of variables used.
3

5. General-Purpose Language

From system programming to photo editing software, the C programming language is


used in various applications. Some of the common applications where it’s used are as
follows:

 Operating systems: Windows, Linux, iOS, Android, OXS


 Databases: PostgreSQL, Oracle, MySQL, MS SQL Server, etc.

6. Rich set of built-in Operators

It is a diversified language with a rich set of built-in operators which are used in
writing complex or simplified C programs.

7. Libraries with Rich Functions

Robust libraries and functions in C help even a beginner coder to code with ease.

8. Middle-Level Language

As it is a middle-level language so it has the combined form of both capabilities of


assembly language and features of the high-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.

10. Easy to Extend

Programs written in C language can be extended means when a program is already


written in it then some more features and operations can be added to it.

2.Explain various flow control statements in C with examples.

ANS.

Flow control refers to the execution order of statements or instructions in a program.


It allows developers or programmers to control the flow and sequence of code
execution based on certain conditions or criteria. Flow control statements are used to
make decisions, repeat blocks of code, and jump to specific sections of code.

There are several types of flow control statements commonly used in C programming:

1.

Conditional Statements: These statements allow the program to make


decisions based on a condition. The most commonly used conditional
statements are:
4

2.

 if statement: Executes a block of code if a certain condition is true.


 if-else statement: Executes one block of code if a condition is true and another block
if the condition is false.
 else-if statement: Executes one block of code if a condition is true and another block
if the other condition is true.
 nested-if statement: It has if statements inside the another if statement.
 switch statement: Allows for multiple branches of execution based on different
values.

3.

Looping Statements: Looping statements allow a block of code to be repeated


multiple times. The most commonly used looping statements are:

4.

 for loop: Executes a block of code for a fixed number of iterations.


 while loop: Repeats a block of code as long as a certain condition is true.
 do-while loop: Repeats a block of code at least once, and then continues repeating
as long as a certain condition is true.

5.

Control Transfer Statements: These statements change the normal flow of


execution within a program. These statements are also called as Jumping
statements.

6.

 break statement: Terminates the execution of a loop or switch statement.


 continue statement: Skips the current iteration of a loop and continues with the
next iteration.
 goto statement: It transfers the control from one part of the code to another
labeled part.
 return statement: Ends the execution of a function and returns a value to the caller.

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.

The function is a named section of the program which contains organised


reusable code to perform a task.
5

The different categories of user-defined functions in C are as follows:

 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.

(ii) Partial array initialization:- Partial array initialization is possible in c language. If


the number of values to be initialized is less than the size of the array, then the
elements will be initialized to zero automatically. Ex:- int a[5]={10,15; Even though
compiler allocates 5 memory locations, using this declaration statement; the compiler
initializes first two locations with 10 and 15, the next set of memory locations are
automatically initialized to 0's by compiler . Partial Array Initialization Initialization
with all zeros:- Ex:- int a[5]={0}(iii) Initialization without size:- Consider the
declaration along with the initialization. Ex:- char b[]={'C','O','M','P','U','T','E','R'}

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.

Declaration of Structure Variables Separately


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;

};

struct structName struct_var1, struct_var2;

Example

struct bookStore

// structure definition

char storeName
7

int totalBooks;

char storeLicense[20];

};

int main()

struct bookStore storeA, storeB; // structure variables;

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

(b) List out the difference between unions and


structures..

ANS.. there is a specific memory location for every input


data member. Thus, it can store multiple values of the
various members. In the case of a Union, there is an
allocation of only one shared memory for all the input data
members. Thus, it stores one value at a time for all of its
members .
Difference Between Structure and Union
Parameter Structure Union

Keyword A user can deploy the keyword struct to A user can deploy the keyword union to
define a Structure. define a Union.

Internal The implementation of Structure in In the case of a Union, the memory


Implementation C occurs internally- because it allocation occurs for only one member
contains separate memory locations with the largest size among all the
allotted to every input member. input variables. It shares the same
location among all these
members/objects.

Accessing Members A user can access individual members at a A user can access only one member at a
given time. given time.

Syntax The Syntax of declaring a Structure The Syntax of declaring a Union in C


in C is: is:
struct [structure name] union [union name]

{ {

type element_1; type element_1;

type element_2; type element_2;

. .

. .

} variable_1, variable_2, …; } variable_1, variable_2, …;

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

the size of its data members. members.

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.

Storage of In the case of a Structure, there In the case of a Union, there is an


Value is a specific memory location for allocation of only one shared memory
every input data member. Thus, it for all the input data members. Thus,
can store multiple values of the it stores one value at a time for all
various members. of its 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.

7. Explain the difference between statics


memory allocation and dynamic
Memory allocation in C . Explain various dynamic
memory allocation function
In C.

ANS.IN static memory allocation, while executing a


program, the memory cannot be changed. In dynamic
memory allocation, while executing a program, the
memory can be changed. Static memory allocation is
preferred in an array. Dynamic memory allocation is
preferred in the linked list.
10

Difference between Static and Dynamic Memory


Allocation
S.No Static Memory Allocation Dynamic Memory Allocation

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.

3 In static memory allocation, while In dynamic memory allocation, while executing


executing a program, the memory cannot a program, the memory can be changed.
be changed.

4 Static memory allocation is preferred Dynamic memory allocation is preferred in the


in an array. linked list.

5 It saves running time as it is fast. It is slower than static memory allocation.

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.

8 Static memory allocation is less Dynamic memory allocation is more efficient


efficient as compared to Dynamic memory as compared to the Static memory allocation.
allocation.

9 This memory allocation is simple. This memory allocation is complicated.

.
11
i
THE END

You might also like