C
C
INTERNAL ASSIGNMENT
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.
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.
➢ 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): }
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;
Question.3. Answer:
Question.4 Answer :
Question. 5 Answer:
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.
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.
Question.6 Answer :
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);`