FYUG EVEN SEMESTER EXAM, 2025 COMPUTER SCIENCE (2nd Semester)

Course No: CSCDSM-151

Subject: Programming with C

Full Marks: 70

Exam Year: 2025

UNIT-I

1. (a) Define keyword. What is the importance of keywords in C? [2 Marks]

Definition: Keywords are reserved words in C that have a predefined meaning to the compiler. They cannot be used as identifiers (like variable or function names).

Importance: Keywords form the basic syntax and structure of the C language, allowing the compiler to understand commands such as loops (for), data types (int), and control flows (if/else).

1. (b) Define operator. List the various types of operator in C. [2 Marks]

Definition: An operator is a symbol that tells the compiler to perform specific mathematical or logical manipulations on data.

Types of Operators:

  • Arithmetic Operators (+, -, *, /, %)
  • Relational Operators (==, !=, >, <)
  • Logical Operators (&&, ||, !)
  • Assignment Operators (=, +=, -=)
  • Increment/Decrement Operators (++, --)

1. (c) Write down the general format of: (i) for loop, (ii) GOTO. [2 Marks]

(i) for loop format:

for (initialization; condition; increment/decrement) {
// statements

}

(ii) GOTO format:

goto label;
...
label:
// statements

2. (a) Explain the decision making statement in C with an example. [10 Marks]

Decision making statements allow a program to execute specific blocks of code based on whether a condition is true or false.

The if-else Statement: This is the most common decision statement.

#include <stdio.h>

int main() {
int age = 20;
if (age >= 18) {
printf("Eligible to vote.");
} else {
printf("Not eligible.");
}
return 0;
}

2. (b) (i) Short note on history of C. (ii) Program to calculate simple interest. [5+5=10 Marks]

History: C was developed by Dennis Ritchie at AT&T Bell Labs in 1972. It was designed to build the Unix operating system and evolved from earlier languages like B and BCPL.

Simple Interest Program:

#include <stdio.h>

int main() {
float p, r, t, si;
p = 1000; r = 5; t = 2; // Example values
si = (p * r * t) / 100;
printf("Simple Interest = %f", si);
return 0;
}

UNIT-II

3. (a) Declare a float array of size 5 and assign values. [2 Marks]

float arr[5] = {1.1, 2.2, 3.3, 4.4, 5.5};

3. (b) How character array is declared? Give example. [2 Marks]

A character array is declared using the char data type followed by the array name and size in square brackets.

char name[10] = "Hello";

4. (a) What is meant by Recursive function? Write a program for factorial. [2+8=10 Marks]

Recursion: A function that calls itself to solve a smaller version of the same problem is known as a recursive function.

#include <stdio.h>

int factorial(int n) {
if (n == 0) return 1;
else return (n * factorial(n - 1));
}
int main() {
printf("Factorial of 5: %d", factorial(5));
return 0;
}

UNIT-III

5. (b) Differentiate between call by value and call by reference. [2 Marks]

Call by Value Call by Reference
Passes a copy of the actual parameter. Passes the address of the actual parameter.
Changes inside function do not affect original values. Changes inside function affect the original values.

6. (a) (iii) C program to swap two numbers using pointer. [5 Marks]

#include <stdio.h>

void swap(int *a, int *b) {
int temp = *a;
*a = *b;
*b = temp;
}
int main() {
int x = 10, y = 20;
swap(&x, &y);
printf("x=%d, y=%d", x, y);
return 0;
}

UNIT-IV

7. (a) Compare structures and union. [2 Marks]

Structure Union
Every member has its own memory location. All members share the same memory location.
Total size is the sum of sizes of all members. Total size is the size of the largest member.

8. (a) (ii) C program to store and print employee info using structure. [8 Marks]

#include <stdio.h>

struct Employee {
int id;
char name[30];
float salary;
};
int main() {
struct Employee e = {101, "Sujan Roy", 50000.0};
printf("ID: %d, Name: %s, Salary: %.2f", e.id, e.name, e.salary);
return 0;
}

UNIT-V

9. (a) What are the files in C language? How many types of files are in C? [2 Marks]

A file is a place on a disk where a group of related data is stored. In C, there are primarily two types: Text files and Binary files.

10. (a) (i) How to open a file? List standard I/O opening modes. [3 Marks]

Files are opened using the fopen() function.

Modes:

  • "r": Open for reading
  • "w": Open for writing (creates new or overwrites)
  • "a": Open for appending
  • "r+": Open for both reading and writing

Knowlet Exam Strategy & Tips

  • Diagrams: Always draw flowcharts for decision-making (if-else, switch) and loop structures.
  • Structure vs Union: This is a high-frequency question. Remember to mention that Unions are memory efficient.
  • Pointers: When swapping or using arrays with pointers, ensure you use the dereference operator (*) correctly.
  • Common Mistake: Forgetting the & in scanf() for non-array variables.

Key Formulas/Syntax:

Simple Interest = (P * R * T) / 100
Pointer Syntax: data_type *pointer_name;

Prepared by Knowlet for Academic Excellence.