0% found this document useful (0 votes)
3 views8 pages

CS3251 - Prgramming in C SET II

This document outlines the B. Tech. Degree Internal Assessment Test II for the Programming in C course, including details on the exam structure, duration, and marking scheme. It contains questions on various C programming concepts such as functions, pointers, recursion, structures, and memory allocation, along with example programs. The document also includes a Bloom's Taxonomy classification for course outcomes related to web and database applications.

Uploaded by

kathiravan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views8 pages

CS3251 - Prgramming in C SET II

This document outlines the B. Tech. Degree Internal Assessment Test II for the Programming in C course, including details on the exam structure, duration, and marking scheme. It contains questions on various C programming concepts such as functions, pointers, recursion, structures, and memory allocation, along with example programs. The document also includes a Bloom's Taxonomy classification for course outcomes related to web and database applications.

Uploaded by

kathiravan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 8

Reg.

No:

B. Tech. DEGREE INTERNAL ASSESSMENT TEST - II


April / May – 2025
SECOND SEMESTER
CS3251 – PROGRAMMING IN C (SET – II)
DEPARTMENT OF INFORMATION TECHNOLOGY
(Regulations - R2021)
Duration: 3 Hours Answer ALL Questions. Maximum: 100 Marks
PART – A (10 2 = 20 Marks)
ANSWER KEY (CSE AND IT)

Define function. How will you declare it?

A function is a block of code that performs a specific task. It improves modularity


1. and code reuse 2 BL1 CO3
int add(int a, int b);

List the advantage of recursion.

2.  Simplifies complex problems like tree traversal, factorial, Fibonacci, etc. 2 BL1 CO3

 Reduces the need for complex loop and stack operations.


What is the difference between an array and pointer?

3. 2 BL2 CO3

Differentiate between call by value and call reference.

4. 2 BL2 CO4

What is a Pointer? How a variable is declared to the pointer?


5. 2 BL1 CO4
Definition: A pointer is a variable that holds the address of another variable.
What is structure? Write the syntax for structure
6. Definition: A structure is a user-defined data type that allows grouping variables of 2 BL1 CO4
different types under one name.
Define nested structure.
7. 2 BL2 CO4
A nested structure is a structure that contains another structure as a member.
Difference between array and structures.

8. 2 BL1 CO5

What is malloc & Calloc with its syntax?


malloc: Allocates a block of memory without initializing.
9. ptr = (cast_type *) malloc(size_in_bytes); 2 BL2 CO5
calloc: Allocates and initializes memory to zero.
ptr = (cast_type *) calloc(num_elements, size_of_each_element);
Define Singly Linked list.
10. A Singly Linked List is a linear data structure where each element (node) contains 2 BL2 CO5
data and a pointer to the next node.


PART – B (5 16 = 80 Marks)
Explain about pointers and write the use of pointers in arrays with
suitable example.
Pointers are variables that store memory addresses. A pointer to an array
points to the first element of the array.
#include <stdio.h>
int main() {
int arr[] = {10, 20, 30, 40};
11. A int *ptr = arr; 16 BL3 CO3

for (int i = 0; i < 4; i++) {


printf("Element %d: %d\n", i, *(ptr + i));
}

return 0;
}
OR
11. B What is recursion? Write a C program to find the sum of the 16 BL3 CO3
digits, to find the factorial of a number and binary search using
recursion.
Recursion is a technique where a function calls itself.
int sumDigits(int n) {
if (n == 0) return 0;
return (n % 10) + sumDigits(n / 10);
}
Factorial using Recursion:
int factorial(int n) {
if (n == 0) return 1;
return n * factorial(n - 1);
}
Binary Search using Recursion:
int binarySearch(int arr[], int low, int high, int key) {
if (low > high) return -1;
int mid = (low + high) / 2;
if (arr[mid] == key) return mid;
else if (key < arr[mid]) return binarySearch(arr, low, mid - 1,
key);
else return binarySearch(arr, mid + 1, high, key);
}
Explain in detail about function and its types in C with example
program.

Functions in C are reusable blocks of code. Types:

1. No arguments, no return value


2. Arguments, no return value
3. No arguments, return value
4. Arguments and return value
12. A 16 BL3 CO4
#include <stdio.h>
int add(int a, int b) {
return a + b;
}
int main() {
int result = add(5, 3);
printf("Sum = %d\n", result);
return 0;
}

OR
Explain the concept of pass by value and pass by reference. Write a
C program to swap the content of two variables using pass by
reference.
Pass by Value: Copies the value (default in C)
Pass by Reference: Uses pointers to directly modify original variables

Swap using Pass by Reference:

#include <stdio.h>
void swap(int *x, int *y) {
12. B int temp = *x; 16 BL3 CO3
*x = *y;
*y = temp;
}
int main() {
int a = 10, b = 20;
swap(&a, &b);
printf("a = %d, b = %d\n", a, b);
return 0;
}

13. A Explain in detail about various storage class with suitable example 16 BL2 CO4
 auto: Default for local variables

 register: Suggests storing in CPU register

 static: Retains value across function calls

 extern: Declares global variables across files

#include <stdio.h>

void testStatic() {

static int x = 0;

x++;

printf("x = %d\n", x);

int main() {

testStatic();

testStatic();

return 0;

OR
13. B(i) Explain about singly linked list with suitable example C program. 8 BL2 CO4
#include <stdio.h>
#include <stdlib.h>

struct Node {
int data;
struct Node* next;
};

void display(struct Node* head) {


while (head != NULL) {
printf("%d -> ", head->data);
head = head->next;
}
}
int main() {
struct Node* head = malloc(sizeof(struct Node));
head->data = 10;
head->next = malloc(sizeof(struct Node));
head->next->data = 20;
head->next->next = NULL;
display(head);
return 0;
}
Discuss about dynamic memory allocation with suitable example C
program
#include <stdio.h>
#include <stdlib.h>

int main() {
int *arr, n;
printf("Enter size: ");
scanf("%d", &n);
B(ii) 8 BL2 CO4
arr = (int*) malloc(n * sizeof(int));
for (int i = 0; i < n; i++) {
arr[i] = i + 1;
printf("%d ", arr[i]);
}

free(arr);
return 0;
}

Explain in detail about Union with suitable example program.


Unions share memory for all members.
#include <stdio.h>
union Data {
int i;
float f;
};
14 A 16 BL2 CO5
int main() {
union Data data;
data.i = 10;
printf("i = %d\n", data.i);
data.f = 22.5;
printf("f = %.2f\n", data.f);
return 0;
}
OR
14. B Write a C program to store the employee information using 16 BL2 CO5
structure and search a particular employee using Employee number.
#include <stdio.h>
#include <string.h>

struct Employee {
int id;
char name[30];
};

int main() {
struct Employee emp[3] = {{101, "John"}, {102, "Alice"}, {103,
"Bob"}};
int searchId;
printf("Enter ID to search: ");
scanf("%d", &searchId);

for (int i = 0; i < 3; i++) {


if (emp[i].id == searchId) {
printf("Employee Found: %s\n", emp[i].name);
return 0;
}
}
printf("Employee not found.\n");
return 0;
}

15 A Explain in detail about structure (Nested structure, Pointer and 16 BL2 CO5
structure, array of structure) in c with example program,
Nested Structure, Pointer to Structure, Array of Structure:
#include <stdio.h>

struct Date {
int day, month, year;
};

struct Student {
int id;
char name[30];
struct Date dob; // Nested structure
};

int main() {
struct Student students[2] = {
{1, "John", {1, 1, 2000}},
{2, "Alice", {2, 2, 2001}}
};
struct Student *ptr = &students[0]; // Pointer to structure
printf("Student: %s, DOB: %d/%d/%d\n", ptr->name, ptr-
>dob.day, ptr->dob.month, ptr->dob.year);
return 0;
}

OR
Write a C program to store the employee information using
structure and search a particular employee using employee number?
#include <stdio.h>
#include <string.h>

struct Employee {
int id;
char name[30];
};

int main() {
struct Employee emp[3] = {{101, "John"}, {102, "Alice"}, {103,
"Bob"}};
15. B(i) 8 BL1 CO5
int searchId;
printf("Enter ID to search: ");
scanf("%d", &searchId);

for (int i = 0; i < 3; i++) {


if (emp[i].id == searchId) {
printf("Employee Found: %s\n", emp[i].name);
return 0;
}
}
printf("Employee not found.\n");
return 0;
}
B(ii) Write a program to print student grade using structure / Write a C 8 BL5 CO5
program to create a mark sheet for students using structure.
#include <stdio.h>

struct Student {
int id;
char name[30];
float marks;
};

int main() {
struct Student s = {1, "John", 85.5};
char grade;

if (s.marks >= 90) grade = 'A';


else if (s.marks >= 75) grade = 'B';
else if (s.marks >= 60) grade = 'C';
else grade = 'F';

printf("Student: %s\nGrade: %c\n", s.name, grade);


return 0;
}

BL – Bloom’s Taxonomy Levels (1 - Remembering, 2 - Understanding, 3 – Applying, 4 – Analyzing, 5


– Evaluating, 6 - Creating)

COURSE OUTCOME DETAILS


CO3 Design and deploy simple web applications.
CO4 Create simple database applications.
CO5 Handle multimedia components

SUBJ. INCHARGE HOD PRINCIPAL

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy