0% found this document useful (0 votes)
4 views10 pages

C

The document outlines the internal assignment details for the Bachelor of Computer Applications (BCA) program, specifically for the Programming in C course. It includes two sets of assignments with specific questions and marks distribution, covering topics such as features of C, flow control statements, functions, arrays, structures, and memory allocation. Each assignment requires comprehensive answers with a word count guideline for certain questions.

Uploaded by

notiyadav007
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)
4 views10 pages

C

The document outlines the internal assignment details for the Bachelor of Computer Applications (BCA) program, specifically for the Programming in C course. It includes two sets of assignments with specific questions and marks distribution, covering topics such as features of C, flow control statements, functions, arrays, structures, and memory allocation. Each assignment requires comprehensive answers with a word count guideline for certain questions.

Uploaded by

notiyadav007
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/ 10

Directorate of Online Education

INTERNAL ASSIGNMENT

SESSION AUGUST 2023


PROGRAM BACHELOR OF COMPUTER APPLICATIONS (BCA)
SEMESTER I
COURSE CODE & NAME DCA1102 – PROGRAMMING IN C
CREDITS 4
NUMBER OF ASSIGNMENTS & 02
MARKS 30 Marks each
Note:
• There will be two sets of assignments for every course and all questions are compulsory in both
sets.
• Average of both assignments’ marks scored will be considered as Internal Assessment Marks.
• Answers for 10 marks questions should be approximately of 400-500 words.

Set - I
Q.No Questions Marks Total Marks
1. Describe various features of the C programming language. 10 10
2. Explain various flow control statements in C with examples. 10 10
3. Define a function. List and explain the categories of user-defined 2+8 10
functions.
Set - II
Q.No Questions Marks Total Marks
4. Define an array. How to initialize a one-dimensional array? Explain with 2+4+4 10
suitable examples.
5. (a) Define Structure and write the general syntax for declaring and 5+5 10
accessing members.
(b) List out the differences between unions and structures.
6. Explain the difference between static memory allocation and dynamic 5+5 10
memory allocation in C. Explain various dynamic memory allocation
function in c.

Mail id: [email protected]


Phone: +91 79966 00444 (Toll Free)
Directorate of Online Education

Set-1
 Question.1 Answer:

The C programming language is a powerful and widely used language known for its
efficiency and low-level programming capabilities. Here are various features of the C
programming language:

1. Procedural Language:
• C is a procedural programming language, which means if follows a top-down
approach in program design. Program are composed of function that perform
specific tasks.
2. Low-Level Manipulation:
• C allows direct manipulation of pointers and addresses, providing low-level
access to memory management is required.
3. Structured Language:
• C supports structured programming through the use of functions and code
blocks, facilitating modular and organized code development.
4. Portability:
• C programs are highly portable across different platforms, as long as the
compiler for that platform is available. This portability is due to the
standardized nature of the language.
5. Efficiency and Speed:
• C is known for its efficiency and speed, making it suitable for system
programming, embedded systems, and application where performance is
critical.
6. Static Typing:
• C is statically typed, meaning that the data types of variables must be
declared before they are used. The can help catch error at compile time,
improving code reliability.
7. Rich Standard Library:
• C comes with a rich set of standard libraries that provide functions for
common task like file handing, input/output operations, sting manipulation,
and more. This makes development faster and more convenient.
8. Pointers and Memory Management:
• C allows the use of pointers, which are variables that store memory
addresses. This enables direct memory manipulation and efficient data
structures. However, it also requires careful memory management to avoid
issues like memory leaks.
9. Bitwise Operations:
• C supports bitwise operations, which are often used in low-level
programming for tasks such as bit manipulation, device control, and network
programming.

Mail id: [email protected]


Phone: +91 79966 00444 (Toll Free)
Directorate of Online Education

10. Inline Assembly:


• C allows the use of inline assembly code, which enables the programmers to
embed assembly language code directly within C code. This is particularly
useful for tasks that requires low-level hardware interactions.

➢ These features collectively make C a versatile language suitable for a wide rang
of application, from operating systems and embedded systems to game
development and high-performance computing.

 Question.2 Answer:

Flow control statements in C are used to control the order in which statements are
executed in a program. Here are the various flow control statements in C with
examples:

1. If Statement:
• The `if` statement is used for conditional execution of code.
Example: int x = 10;
If ( x > 5 ) { printf (“x is grater than 5\n” ); }

2. If-else:
• The ` if-else ` statement allows branching based on a condition.
Example: int y = 3;
If (y % 2== 0 ) {
printf (“y is even\n”);
}else{ printf(“y is odd\n”); }

3. Switch Statement:
• The ` switch ` statement is used for multi-way branching based on the value
of an expression.
Example: char grade = “B”;
Switch(grade) {
Case ‘A’:
Printf(“Excellent \n”);
Break;
Case ‘B’:
Printf(“good \n”);
Break;
Case ‘c’;
Printf(“Average\n”); break; default: printf(“not a valid grade\n): }

Mail id: [email protected]


Phone: +91 79966 00444 (Toll Free)
Directorate of Online Education

4. While Loop:
• The `while` loop is used for repetitive execution while a condition is true.
Example: int count = 0;
while (count < 5 ) {
printf(“Count: %d\n”, count);
count ++;
}
5. For loop:
• The ` for ` loop is a compact way to express a loop with initialization,
condition, and increment/decrement in a single line.
Example: for(int j =0; do { printf(“i:%d\n”,j);I ++; } while (i< 3);

6. Break Statement :
• The ` break ` statement is used to exit form a loop prematurely.
Example: for( int k =0; k < 5; k++) {
if ( k==3 ) {
break;
}
Printf(“k : %d\n”,k);
}
7. Continue Statement:
• The ` continue ` statement is used to skip the rest of the loop body and move
to the next iteration.
Example: for ( int m= 0 ; m < 5; m++) {
if (m == 2) {
continue ;
}
Printf(“m: %d\n”,m);
}
8. Goto Statement:
• The `goto` statement is used to transfer control to a labelled statement within
the same function.
Example : int n =0;
Loop_start:
If (n <3) {
Printf(“n: %d\n”,n);
n++;
goto loop_Start;

Mail id: [email protected]


Phone: +91 79966 00444 (Toll Free)
Directorate of Online Education

 Question.3. Answer:

A function in programming is a reusable and self-contained block of code that. Performs


a specific task or set of tasks. It is designed to be called and executed when needed,
providing modularity and abstraction in the code. Function help break down complex
programs into smaller, more manageable parts.
Here:

• `def` is the keyword used to declare a function.


• ` function_name ` is the name of the function, following the rules for naming
identifiers.
• ` parameters ` are variables that the function takes as input, enclosed in
parentheses.
• The function body is idented and contains the code that defines the
functionality.
• ` return` statement, if present, in used to specify the value the function
produces as output.

Categories of User-Defined Functions:


1. Void function (Functions without Return Values):
• These function perform a task or set of tasks but do not return a value.
Example:
Def greet (name);
Printf(“Hello”,{name}”)
2. Value-Returning Function:
• These function compute a value and return it using the ` return `
statement.
Example:
Def add (a, b);
Return a + b
3. Functions with parameters:
• Functions can take input parameters, allowing them to work with
different data.
Example:
Def square (x):
Return x *x

Mail id: [email protected]


Phone: +91 79966 00444 (Toll Free)
Directorate of Online Education

4. Function without Parameters:


• Function can be defined without any input parameters.
Example:
def print_hello();
print ( “Hello!”)
5. Recursive Functions:
• These functions call themselves either directly or indirectly.
Example: def factorial(n ): if n ==0 or n ==1; return 1
Else: return n * factorial(n-1)
6. Function with Default Parameters:
• Parameters can have default values, making them optional when the
function is called.
Example:
Def power ( base, exponent = 2 ) :
Return base ** exponent
7. Function with Variable Number of Arguments:
• Function can accept a variable number of arguments using `* args ` and
**kwargs`.
Example:
Def calculate_sum(*numbers): return sum(numbers)

These categories illustrate the versatility and flexibility of user-defined function in


Programming, enabling developers to create modular and efficient code.

 Question.4 Answer :

Definition of an Array: An array is a data structure that stores a collection of


elements, where each element can be accessed using an index or a key. Arrays
provide a way o organize and store data in a contiguous block of memory, allowing
for efficient access and manipulation of elements.

Initialization of a One-Dimensional Array: In most programming languages, you


can initialize a one-dimensional array by specifying the size of the array and assigning
values to each element. The syntax may vary between programming language, but the
basic idea to declare an array variable, specify its size, and then assign values to
individual elements.

1. Declaration: Before using an array, it needs to be declared. Declaration involves


specifying the data type of the elements and providing a name for the array.

Mail id: [email protected]


Phone: +91 79966 00444 (Toll Free)
Directorate of Online Education

Example: int myArray[5];


2. Initialization with Value:
After declaring an array, it can be initialized by assigning value to its elements. The values
are enclosed with curly braces `{}` in a comma-separated list
Example: int myArray[5] ={1,2,3,4,5}
3. Accessing Array Elements:
Elements is an array are accessed using indices, starting form 0. For example,
`myArray[0]` represents the first element, `myArray[1]` the second, and so on.

Example : printf(“Element at index 2 : “&d” , myArray[2]);

4. Iterating Through an Array:


Loops, such as `for` loops, are commonly used to iterate through array elements.
Example: for (int I =0; I <5, i++) {
Printf(“Element at index %d: %d\n”,i, myarray[i]);}
EXAMPLE:
#include <stdio.h>
Int main() {
Int myarray[5]= {1,2,3,4,5};
For (int i= 0; i<5, i++){
Printf(“Element at index %d: %d\n”, I, myArray[i];
}
Return 0;
}

 Question. 5 Answer:

A) Definition of Structure and General Syntax:


A structure is a composite data type in programming that allows the grouping of
variables of different data types under a single name. Each variable within a
structure is referred to as a member. Structures provide a way to organize related
pieces of information into a single unit.

Mail id: [email protected]


Phone: +91 79966 00444 (Toll Free)
Directorate of Online Education

The general syntax for declaring a structure involves using the `struct` keyword
followed by the structure name. Members of the structure are declared inside cruly
braces. To access members, an instance of the structure is created, and members
are accessed using the dot (`.`) operator.

B) Differences between Unions and Structures:


1. Memory Allocation:
• Allocate memory for each member separately. The total size of the
structure is the sum of the sizes of its members.
• Share the same memory location for all members. The size of the union
is determined by the largest member.
2. Memory Usage:
• Memory is allocated for each member, and all members can be used
simultaneously
• Only one member can be used at a time. Memory is shared among
members.
3. Memory Access:
• Members can be accessed independently.
• Only one member can be accessed at a time. Accessing a different
member may overwrite the value of the previous member.
4. Usage:
• Used when you need to represent a collection of related but distinct
pieces of information.
• Used when you want to save memory by sharing the same space for
different data types, and only one types of data needs to be stored at a
time.
5. Initialization:
• All members can be initialized individually.
• Only the first member is initialized, and the values of other members
are undefined until explicitly set.

These differences highlight the distinct characteristics and use cases of structures and unions
in programming. Structures are more versatile for representing related data, while unions are
useful for conserving memory when only one piece of information is needed at a time.

Mail id: [email protected]


Phone: +91 79966 00444 (Toll Free)
Directorate of Online Education

 Question.6 Answer :

A) Difference Between Static Memory Allocation and Dynamic Memory


Allocation:

Static Memory Allocation:


1. Definition: In static memory allocation, memory is allocated at compile-time,
and the size of the memory is fixed throughout the program’s execution.
2. Scope: Variables with static memory allocation have a global or local scope,
and their memory is determined before the program starts running.
3. Examples: Arrays and static variables are examples of statically allocated
memory.
4. Advantages: Memory allocation and deallocation are handled automatically by
the compiler. It is straightforward and efficient for small-sized data structures.
5. Disadvantages: Fixed size can be a limitation. Memory usage cannot be adapter
during runtime.

Dynamic Memory Allocation:


1. Definition: In dynamic memory allocation, memory is allocated at runtime, and
the size of the memory can be changed during the program’s execution.
2. Scope: Memory is allocated using pointers and functions like `malloc` and it
persists until explicitly freed using functions like `free`.
3. Examples: Dynamic memory allocation is commonly used for creating data
structures like linked lists, trees, and resizable arrays.
4. Advantages: Flexibility in memory usage, allowing for efficient use of memory
and adaptation to changing requirements.
5. Disadvantages: Manual memory management is required ,and improper use
can lead to memory leaks or segmentation faults.

B) Various Dynamic Memory Allocation Functions is C:


1. Malloc (Memory Allocation ):
• Function: `void* malloc(size_t size);`
• Purpose: Allocates a specified number of bytes of memory and returns
a pointer to the beginning of the allocated block.
• Example: `int* arr =(int*)malloc(5 * sizeof (int));1
2. Calloc(Contiguous Allocation);
• Function: `void* calloc(size_t num_elements, size_t elemetns_size);`
• Purpose: Allocated memory for an array of elements,initializes all bytes
to zero and returns a pointer to the beginning of the allocated block.
• Example: `int * arr=(int*)calloc(5,sizeof (int));`

Mail id: [email protected]


Phone: +91 79966 00444 (Toll Free)
Directorate of Online Education

3. Realloc(Reallocate Memory):
• Function:`void* realloc(void* ptr,size_t new_size);`
• Purpose: Changes the size of the previously allocated block of memory. It
may move the block to a new location if necessary.
• Example: ` arr = (int*) realloc(arr, 10 * sizeof(int));`
4. Free(Free Memory):
• Function: `void free(void* ptr);`
• Purpose:Deallocates the memory block previously allocated by `
malloc`, `calloc` or `realloc`.
• Example: `free(err);`

Mail id: [email protected]


Phone: +91 79966 00444 (Toll Free)

You might also like