[go: up one dir, main page]

0% found this document useful (0 votes)
11 views28 pages

Question Bank ES Cs201(C Programming) (4)

The document contains a series of multiple-choice questions (MCQs) and descriptive questions related to programming concepts, particularly in C language. It covers topics such as memory types, operators, flowcharts, loops, data structures, and program execution. Additionally, it includes practical programming tasks and explanations of key programming principles and constructs.

Uploaded by

Soumyadip Maity
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)
11 views28 pages

Question Bank ES Cs201(C Programming) (4)

The document contains a series of multiple-choice questions (MCQs) and descriptive questions related to programming concepts, particularly in C language. It covers topics such as memory types, operators, flowcharts, loops, data structures, and program execution. Additionally, it includes practical programming tasks and explanations of key programming principles and constructs.

Uploaded by

Soumyadip Maity
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/ 28

MODULE-1

1. What type of memory is used to store frequently accessed data for faster processing?[CO1]
A. Cache Memory B. RAMC. ROM D. Hard Disk
2. Which of the following is NOT a keyword in C?[CO1]
A. Int B. float C. double D. function
3. What does an arrow indicate in a flowchart?[CO1]
A. Start B. Decision C. Flow of Process D. End
4. Which memory is volatile?[CO1]
A. RAM B. ROM C. Hard disk D. DVD
5. Which operator is used for bitwise AND operation?[CO1]
A. & B. && C. | D. ||
6. What will be the output of 5 % 2 in C?[CO1]
A. 2 B. 1 C. 0 D. 5
7. How many times i value is checked in the following C program?[co1]
#include <stdio.h>
int main()
{
int i = 0;
while (i < 3)
i++;
printf("In while loop\n");
}[CO1]
A. 2 B. 3 C. 4 D. 1
8. What is the correct syntax for a for loop in C?[CO1]
A. for(initialization, condition, increment) B. for(initialization; condition; increment)

C. for condition (initialization, increment) D. loop for(initialization; condition;


increment)

9. Which of the following is an entry-controlled loop?[co1]

a. do-while b. while c. switch d. goto

10. Which generation of computers used vacuum tubes?[CO1]

a.first b.second c.third d.fourth

11. In which year was the first laptop, Grid Compass 1101, introduced?[CO1]

a. 1975 b. 1982 c. 1990 d. 2000

12. What is the correct extension for a C program file?[CO1]

a.(.cpp) b.(.c) c.(.java) d.(.cs)


13. The hexadecimal number system has how many unique digits?[CO1]

a.8 b.10 c.16 d.32

14. What will be the output of the program?

#include<stdio.h>

int main()

typedef int LONG;

LONG a=4;

LONG b=68;

float c=0;

c=b;

b+=a;

printf("%d,", b);

printf("%f\n", c);

return 0;

}[CO1]

a. 72, 68.000000 b. 72.000000, 68 c. 68.000000, 72.000000 d. 68, 72.000000

15. Which of the following is responsible for executing instructions in a computer system?

A) Hard Disk
B) RAM
C) Processor
D) Compiler

Answer: C) Processor

16. Where is a program stored before execution?

A) Hard disk
B) RAM
C) ROM
D) Cache

Answer: B) RAM

17. Which of the following is NOT an example of system software?

A) Operating System
B) Compiler
C) Word Processor
D) Device Driver
Answer: C) Word Processor

18. The binary equivalent of the decimal number 25 is:

A) 11001
B) 10101
C) 11111
D) 10011

Answer: A) 11001

19. What is the hexadecimal representation of the binary number 101011?

A) 2B
B) AB
C) 1A
D) 3D

Answer: A) 2B

20. What is an algorithm?

A) A type of data structure


B) A programming language
C) A step-by-step procedure to solve a problem
D) A storage device

Answer: C) A step-by-step procedure to solve a problem

21. Which of the following is a graphical representation of an algorithm?

A) Pseudocode
B) Flowchart
C) Source code
D) Binary tree

Answer: B) Flowchart

22. What does a compiler do?

A) Converts high-level language code into machine code


B) Executes the program directly
C) Converts machine code into high-level code
D) Checks for logical errors

Answer: A) Converts high-level language code into machine code

23. Object code is generated after which phase?

A) Writing source code


B) Compilation
C) Debugging
D) Execution

Answer: B) Compilation

24. What will be the result of the expression 10 + 3 * 2 in most programming languages?
A) 26
B) 16
C) 23
D) 20

Answer: C) 16

25. In programming, which operator has the highest precedence?

A) Addition (+)
B) Multiplication (*)
C) Parentheses ()
D) Subtraction (-)

Answer: C) Parentheses ()

26. What will be the output of the expression 5 + 4 / 2?

A) 4.5
B) 4
C) 7
D) 9

Answer: C) 7

27. The modulus operator (%) is used to:

A) Divide two numbers


B) Find the remainder of division
C) Multiply two numbers
D) Compare two numbers

Answer: B) Find the remainder of division

28. What will be the result of 3 + 4 * (2 - 1)?

A) 9
B) 10
C) 7
D) 11

Answer: B) 10

5MARKS QUESTIONS

1. Define an operator in C. List and explain any four types of operators with examples.[co1]
2. List and briefly explain the main components of a computer system.[co1]
3. Draw and explain briefly two simple flowchart i)calculating the area of a rectangle and
ii)Calculate the area of circle .[co1]
4. Convert the following and explain the process:(a) Binary 10110.1100 to Decimal (b) Decimal 47
to Hexadecimal
5. Explain the difference between ‘for’, ‘while’ and ‘do-while’ loop in C with example
programs.[co1]
6. What is variable?What are different types of variables which are called storage classes
also?[co1][1+4]
7. Explain with an example how nested if statements work in C. Write a program to find the
greatest of three numbers using nested if.[2+3]
8. Describe in detail how a C program is executed, from writing source code to generating the final
output. Include the roles of editor, compiler, and linker.
9. Difference between RAM and ROM.
10. Explain the different components of a computer system. Discuss their roles in program execution.
11. What is c language and its characteristics
12. What is the identifier and rules to declare the identifier name.
13. Convert the following numbers as specified and explain the process of conversion:
a) (101110)₂ to decimal
b) (47)₈ to binary
c) (2F)₁₆ to decimal
d) (1001)₂ to octal
e) (59)₁₀ to binary

14. What is type casting and its types.


15. Differentiate between algorithm and flowchart.
16. Explain the operator precedence and associativity in C in this problem. Evaluate the following
expression step by step:

int a = 10, b = 5, c = 2, result;


result = a + b * c - (a / c);

10MARKS

1. Write a C program that accepts a number from the user and checks whether it is:
 Even or Odd
 Positive or Negative
 Divisible by 5 or not
Use appropriate conditional statements.[CO1][2+2+1]
2. A.Create a program using nested loops that generates the following pattern (example for n = 5)
[5]
*
**
***
****
*****
B.Create a pattern shown below using loops[5] 1
23
456
7 8 9 10
11 12 13 14 15
3. Create a calculator(+, -, *, / , %) using switch case(create it in menu driven format).
Example: press 1 for addition
Press 2 for subtraction Press 3
for multiplication Press 4
for division
Press 5 for modulus
Press 6 for menu
Press 7 for exit
and also provide all the options in output. [10]
4. Explain the concept of operator precedence and associativity in C with table. Why is it important
in expression evaluation? Provide examples.[co1][5+5]
5. What are the different types of operators in c explain with examples
6. Explain the conversion process between binary and decimal, binary and octal, and binary and
hexadecimal.

7. Explain the operator precedence and associativity in C with a detailed example


8. Write an algorithm and draw a flowchart to check whether a given number is prime or not.
9. Write a C program to find maximum between two numbers using conditional operator.

MODULE-2
MCQ

1. What will be the output of printf("%d", strlen("abc"));


a.2 b.3 c.4 d.Error
2. Which data structure is used for linear search?
a. stack b.Array c.Queue d.Tree
3. Which function is used to copy strings in C?
a. strcpy() b.strcat() c.strcmp() d.strcopy()
4. Which loop will execute at least once even if the condition is false initially?
a.for b.while c.do-while d.infinite loop
5. Which of the following can be used to stop a loop immediately?
a) exit b) continue c) break d) stop
6. Which control statement is used for multiple branching based on integer values?
a) goto
b) for
c) switch
d) while
Ans: c
7. In an if statement, what happens if the condition is false?
a) The code after if is skipped
b) All statements are executed
c) The program terminates
d) None of the above
Ans: a
8. Which of these statements about the for loop is incorrect?
a) It is count-controlled
b) Initialization is mandatory
c) It executes a set of instructions repeatedly
d) It can have multiple expressions in its header
Ans: b
9.Which of these statements is true about the switch case statement?
e) It supports conditions with logical operators
f) It only works with integers and characters
g) It evaluates multiple conditions simultaneously
h) It can execute floating-point conditions
Ans: b

10. What is the output of this code

char s1[] = "hello";

char s2[10];
strcpy(s2, s1);
printf("%s", s2);

a) hello
b) s2
c) Compilation error
d) Undefined
Ans: a

11. In Linear Search, the best-case time complexity is:


 O(n)
 O(log n)
 O(1)
 O(n log n)
Ans: c
12. What will the following code print?
char str[5] = "hello";
printf("%s", str);
 hello
 Compilation error
 h
 Undefined behavior
Ans: b (string requires 6 characters including '\0')
13. What is the output of the following?
char *s1 = "abc";
char *s2 = "abc";
if (s1 == s2)
printf("Equal");
else
printf("Not Equal");
 Equal
 Not Equal
 Compilation Error
 Runtime Error
Ans: a (because both point to the same string literal in memory)
14. Output of the following recursive function?
#include <stdio.h>
void main() {
m();
}
void m() {
printf("hi");
m();
}

 Compile time error


 hi
 Infinite hi
 Nothing
Ans: c

15.. Which of the following is used to make decisions in a program?

A) Loop
B) Conditional statement
C) Function
D) Variable

Answer: B) Conditional statement

16. In an if-else statement, when is the else block executed?

A) When the condition is true


B) When the condition is false
C) Always
D) Never
Answer: B) When the condition is false

17. Which of the following is an example of an entry-controlled loop?

A) for loop
B) while loop
C) Both A and B
D) do-while loop

Answer: C) Both A and B

18. Which loop ensures that the body of the loop executes at least once?

A) for loop
B) while loop
C) do-while loop
D) Infinite loop

Answer: C) do-while loop

19. What is an infinite loop?

A) A loop that executes a fixed number of times


B) A loop that never stops executing
C) A loop that executes only once
D) A loop that contains a break statement

Answer: B) A loop that never stops executing

20. Which statement is used to exit a loop prematurely?

A) continue
B) exit
C) break
D) return

Answer: C) break

21. Which of the following statements is true about the if statement?

A) It must always have an else block


B) It can have multiple elif blocks
C) It can only check for equality (==)
D) It executes only once in a program

Answer: B) It can have multiple elif blocks

22. What does the continue statement do in a loop?

A) Exits the loop


B) Skips the rest of the current iteration and moves to the next
C) Repeats the current iteration
D) Stops the execution of the entire program

Answer: B) Skips the rest of the current iteration and moves to the next

23. What will happen if the condition in a while loop is always True?
A) The loop will execute indefinitely
B) The loop will execute only once
C) The program will exit immediately
D) The loop will throw an error

Answer: A) The loop will execute indefinitely

24. Which loop is most suitable for executing a fixed number of times?

A) while loop
B) do-while loop
C) for loop
D) Infinite loop

Answer: C) for loop

25. What is the default behavior of an if statement if no else block is provided?

A) It throws an error
B) It executes normally, and nothing happens if the condition is false
C) It enters an infinite loop
D) It automatically assigns a default value

Answer: B) It executes normally, and nothing happens if the condition is false

26. Which operator is used for checking equality in a conditional statement?

A) =
B) ==
C) !=
D) :=

Answer: B) ==

27. Which of the following is NOT a characteristic of a while loop?

A) It is an entry-controlled loop
B) It executes at least once, even if the condition is false
C) It requires an explicit condition to terminate
D) It can result in an infinite loop if not properly controlled

Answer: B) It executes at least once, even if the condition is false

28. Which loop should be used when the number of iterations is known in advance?

A) while loop
B) for loop
C) do-while loop
D) Infinite loop

Answer: B) for loop

5MARKS
1. State the difference between entry-controlled and exit-controlled loop.[4]
State the difference between count controlled and condition controlled loop.[1]
2. What is two-way selection statement? Explain if, if-else, and cascaded if-else with
examples.[5]
3. Explain the difference between = and == operators with examples.
4. Explain how a switch statement works with an example of menu-based program.
Explain 1D array and 2D array. Differentiate between one-dimensional and two-
dimensional arrays with examples.[2+3]
5. Write the binary search algorithm with a example.
6. Write a program in string to show string length, comparison of two string, copy to
another string upto 4 characters, string lower and string reverse.
7. Differentiate between the for, while, and do-while loops with suitable examples.
8. Write a C program to check whether a number is prime or not using a for loop.
9. Explain the concept of nested loops in C with an example.
10. Explain the use of break and continue statements in loops with examples.
11. Write a C program using a for loop to calculate the factorial of a given number.
12. Write a C program to check whether a given number is positive, negative, or zero using if-
else statements.
13. Explain the working of the switch statement in C with an example.

10MARKS
1. Explain the concept of a nested loop in matrix operations with an example.[5]
Write the program of transpose of a matrix with suitable output.[5]
2. Write the bubble sort algorithm.[5]
Compute the bubble sort: 90, 50, 70, 10, 60, 30.[5]
3. Write a program to sort an array using selection sort with output. Explain each step using
algorithm and an example.[10]
4. Write a program to search an element in an array using linear search.[5]
Explain the difference between linear search and binary search with an example.[5]

What is a selection statement and explain its types breifly.


5. A. What is a table of strings? how the table of string Initialize and declare.
B. Write a C program To initialize the table of strings and display the contents.
6. Write a C program to find the sum of all even and odd numbers separately from 1 to N, where N is
entered by the user. Explain the logic used in your program.
7. Write a C program that takes the total number of classes held and the number of classes attended as
input. The program should check if the student is eligible for exams using conditional statements.
Explain the logic used for decision-making. (Note:- A school requires students to attend at least 75% of
classes to be eligible for exams.)
8. Compare and contrast the if-else statement and the switch statement in C. Write a program that
demonstrates the use of both for solving the same problem.

MODULE-3

1. What is the default return type of a function in C if not specified?

a) void

b) int

c) float

d) double
Answer: b

2. What will be the output of fun(3) if the function prints n and then calls fun(n-1)?

• 123

• 321

• Infinite loop

• 132

Answer: b
3. What is a recursive function?

• A function that returns void

• A function that calls itself

• A function without parameters

• A function called from main only

Answer: b

4. How do you declare a function with no parameters and no return value?

• void fun();

• fun()

• void fun(int)

• int fun();

Answer: a

5. Which is the correct way to pass parameters in call by value?

• int *a

• int a

• int &a

• a=10

Answer: b

6. void swap(int *a, int *b) swaps values by:


• Copying variables
• Calling values by value
• Passing by address (call by reference)
• Using array
⬛ Answer: c
7. How do you pass an array to a function in C?
• By value
• By pointer
• By reference
• Both b and c
⬛ Answer: d
8. What is the output of recursive Fibonacci for fib(4)?
a) 5
b) 3
c) 2
d) 4
⬛ Answer: b
(Fibonacci: 0, 1, 1, 2, 3... → fib(4) = 3)
9. What is the difference between call by value and call by reference?
• Value passes memory address; reference passes copy
• Reference passes address; value passes copy
• Both are the same
• Call by reference uses arrays only
⬛ Answer: b
10. What’s wrong with this
function?
int fun(int n)
{ return fun(n++);
}
• Missing return value
• n is not initialized
• Causes infinite recursion due to lack of base case
• fun is not declared before use
⬛ Answer: c

11. What’s the output of a recursive function with multiple base cases (e.g., if(n==0) return 0;
if(n==1) return 1;)?
• Always returns 0
• Depends on input and recursive logic
• Compilation error
• Cannot be executed
⬛ Answer: b

12. Which of the following demonstrates tail recursion?


• Function calls itself before return
• Function calls itself after return
• Function returns the result of recursive call directly
• Recursion inside a loop
⬛ Answer: c

13. How do you declare a pointer to an integer in C?

A) int p;
B) int *p;
C) pointer<int> p;
D) int &p;
Answer: B) int *p;

14. What is an Array in C language?

a) A group of elements of same data type.

b) An array contains more than one element

c) Array elements are stored in memory in continuous or contiguous locations.

d) All the above.

15. What is the right way to initialize array?

a) int n{} = { 2, 4, 12, 5, 45, 5 }; b) int num[6] = { 2, 4, 12, 5, 45, 5 };

c) int n{6} = { 2, 4, 12 }; d) int n(6) = { 2, 4, 12, 5, 45, 5 };

b) int num[6] = { 2, 4, 12, 5, 45, 5 };

16. What is the index of the first element in a C array?

A) 0
B) 1
C) -1
D) Depends on the array size

Answer: A) 0

17. How do you declare a two-dimensional array in C?

A) int arr[3][4];
B) int arr(3,4);
C) int arr{3,4};
D) int arr[4][3];

Answer: A) int arr[3][4];

18. What will be the output of the following program?

#include <stdio.h>

int main() {

char str[] = "Hello";

printf("%s", str);

return 0;

A) H
B) Hello
C) Hello\0
D) Compilation error

Answer: B) Hello

19. Which of the following statements about strings in C is true?

A) Strings are terminated by a space character


B) Strings are stored as character arrays ending with \0
C) Strings are declared using string datatype
D) Strings cannot be passed to functions

Answer: B) Strings are stored as character arrays ending with \0

20. What is the worst-case time complexity of linear search?

A) O(1)
B) O(log n)
C) O(n)
D) O(n²)

Answer: C) O(n)

21. Binary search works on:

A) Sorted arrays only


B) Unsorted arrays only
C) Arrays of only even length
D) Any type of array

Answer: A) Sorted arrays only

22. Which sorting algorithm repeatedly selects the smallest element and places it in order?

A) Bubble Sort
B) Selection Sort
C) Merge Sort
D) Quick Sort

Answer: B) Selection Sort

23. What is the function of strlen() in C?

a) It concatenates two strings.

b) It returns the length of a string.

c) It compares two strings.

d) It reverses a string.

b) It returns the length of a string.

12. What is the output of the following program?

#include <stdio.h>
int main() {

int x = 10, y = 20;

int *ptr = &x;

ptr = &y;

printf("%d", *ptr);

return 0;

A) 10
B) 20
C) Memory address of y
D) Compilation error

Answer: B) 20

24. What is the output of the following C program?

#include <stdio.h>

int square(int x) {

return x * x;

int main() {

printf("%d", square(4));

return 0;

A) 8
B) 16
C) Compilation error
D) Runtime error

Answer: B) 16

25. How do you pass an array to a function in C?

A) void func(int arr[]);


B) void func(int *arr);
C) void func(int arr[10]);
D) All of the above
Answer: D) All of the above

5MARKS
1. What is a function? Write all aspects of function with its syntax and an example.[1+4]
2. What is recursion? Explain with factorial example.[5]
Compare recursion and iteration with example.[5]
3. Write a function to generate n Fibonacci numbers.[5]
Write a program for Tower of Hanoi for 3 disks.[5]
4. Explain the concept of dynamic memory allocation with example.[5]

5. What are different types of pointers?Explain briefly.


6. Differentiate between a one-dimensional (1-D) and a two-dimensional (2-D) array with examples.
7. Write a C program to find the largest element in a 1-D array.
8. Write a C program to implement the Linear Search algorithm.
9. What is recursion? Explain with an example. Compare recursion and iteration.

10. Explain the working of the Bubble Sort algorithm with an example.
11. Why is Binary Search more efficient than Linear Search for large datasets? Explain with an
example.
10 Marks
1. Compare and contrast character arrays and strings in C. Write a C program to concatenate two strings
without using the strcat() function.
2. Differentiate between call by value and call by reference in functions. Write a program to demonstrate the
difference.
3. Write a recursive function to find the Fibonacci series up to n terms and explain how recursion works
internally.
4. A. What are built-in library functions in C? Give examples of at least three different categories.
B.Explain how arrays are passed to functions in C. Give an example

5. A teacher wants to analyze the marks of students in a class. The teacher needs a program that:
● Accepts marks of N students.

● Finds the highest and lowest marks.

● Sorts the marks in ascending order.

● Searches for a specific student’s mark using Binary Search.

6. Write a C program to implement the above functionalities using arrays, functions, and Binary Search.

10 marks
1. Explain different types of user-defined functions.[10]
2. How Does C Function Work?[5]
Write a program to concatenate two strings using functions.[5] Explain
call by value and call by reference with example.[10] HARD
1. Explain Ackermann function with example in C.[10]

MODULE_4
MCQ
1. What is a
structure in C?
a) Keyword
b) Derived data type
c) Pointer
d) Function
→ b) Derived data type
2. Which keyword is used to define a structure?
a) class
b) record
c) struct
d) structure
→ c) struct
3. File mode "a" stands for:
a) Attach
b) Append
c) Add
d) Allocate
→ b) Append
4. Which function allocates dynamic memory?
a) alloc()
b) malloc()
c) memory_alloc()
d) create()
→ b) malloc()
5. Which keyword is used for dynamic memory deallocation?
a) delete
b) remove
c) free
d) release
→ c) free
6. What does FILE fp mean in C?
a) File pointer
b) File format
c) File structure
d) Function pointer
→ a) File pointer
7. Which is not a valid
file opening mode
in C?
a) r+
b) rb
c) rw
d) a
→ c) rw
8. What does this pointer expression mean: *(*(arr + i) + j)?
a) 2D pointer access
b) Dynamic memory
c) File handle
d) Structure pointer
→ a) 2D pointer access
9. Which header defines malloc()?
a) stdio.h
b) math.h
c) stdlib.h
d) string.h
→ c) stdlib.h MCQ
HARD
10.  If a pointer is incremented, it actually increases by:
a) 1 byte
b) Size of the data type
c) 2 bytes
d) Depends on memory
→ b) Size of the data type
11. What is a structure in C?

A) A built-in datatype
B) A user-defined datatype that groups different data types
C) A loop control structure
D) A pointer variable

Answer: B) A user-defined datatype that groups different data types

12. Which keyword is used to define a structure in C?

A) class
B) struct
C) union
D) record

Answer: B) struct

13. What is the correct syntax for defining a structure in C?


A. struct { int a; float b; };
B. struct MyStruct { int a; float b; };
C. structure MyStruct { int a; float b; };
D. class MyStruct { int a; float b; };

Answer: B) struct MyStruct { int a; float b; };

14. How do you access a member of a structure using a structure variable?

A) variable.member
B) variable->member
C) variable(member)
D) variable{member}

Answer: A) variable.member

15. How do you declare an array of structures?

A) struct Student arr[10];


B) Student arr(10);
C) struct Student[10];
D) array<Student> arr[10];
Answer: A) struct Student arr[10];

16. What is a union in C?

A) A structure with only one data type


B) A user-defined datatype where all members share the same memory location
C) A class in C
D) A structure with different memory locations

Answer: B) A user-defined datatype where all members share the same memory location

17. What does the "a" mode in file operations do?

A) Reads the file


B) Appends to the existing file
C) Overwrites the file
D) Deletes the file

Answer: B) Appends to the existing file

18. What will be the output of the following C code?

#include <stdio.h>

struct student

{ char *name;

};

void main()

struct student s, m;

s.name = "xyz";

m = s;

printf("%s%s", s.name, m.name);

a) Compile time error b) Nothing c) xyz xyz d) Junk


values

19. Which file mode is used to create and write a file?

A) "r"
B) "w"
C) "a"
D) "rw"

Answer: B) "w"
20. What is the key difference between a structure and a union?

A) Structures allocate memory for all members, unions allocate memory for only the largest member
B) Structures can store only integers, unions can store any type
C) Structures use pointers, unions do not
D) Structures cannot have functions, but unions can

Answer: A) Structures allocate memory for all members, unions allocate memory for only the largest member

21.What does fclose() do?

A) Closes the file


B) Deletes the file
C) Reads the file
D) Writes to the file

Answer: A) Closes the file

22. What is the purpose of "r+" mode in fopen()?

A) Open file for reading only


B) Open file for reading and writing
C) Create a new file
D) Append to an existing file

Answer: B) Open file for reading and writing

23. What will be the output of the following code?

#include <stdio.h>

union Data {

int i;

float f;

};

int main() {

union Data d;

d.i = 10;

d.f = 5.5;

printf("%d", d.i);
return 0;

A) 10
B) 5.5
C) Garbage value
D) Compilation error

Answer: C) Garbage value (because both i and f share the same memory)

24.

What is the output of the following code?

#include <stdio.h>
struct Test {
int a;
char b;
};
int main() {
struct Test t = {10, 'A'};
printf("%d %c", t.a, t.b);
return 0;
}

A) 10 A
B) Compilation Error
C) Garbage Value
D) None of the above

Answer: A) 10 A

5 marks
1. Define structure. Write syntax and a simple example.[5]
2. What is a union? How is it different from a structure?[2+3]
3. Explain array of pointers with code.[5]
4. Write a program using a structure to manage student records like name, roll, marks etc.[5]
10 marks
5. Write a program to open, write, read, append and close a file.[10] Moderate
6. Write a program to use dynamic memory allocation for an array using all the functions
for dynamic memory allocation in C from standard library.[10]
7. Explain structure within a structure and array of structures with examples and also
elaborate differences within the two.[6+4]
8. What is a structure in C? How is it different from an array? Explain with an example.
9. Differentiate between struct and union in C with an example.
10. What are the different modes in which files can be opened in C? Explain with examples.
11. Write a C program to define a structure named Student with members: name, roll_no, and marks.
Accept details of a student and display them
12. Write a C program to create a file and write a string into it.
13. Write a C program to demonstrate how memory allocation differs in structures and unions by
creating a structure and a union with the same data members.
14. What is the difference between writing to a file using "w" mode and "a" mode in fopen()?
Explain with examples.

10 MARKS QUESTION

1. A.Write the application/need of union in c.

B.Write the advantages and disadvantages of union.

2. Write a C program to define a structure for the students and then keep the records(Name, Roll No, Marks)
of 5 students.

3. What are nested structures? Write a C program to define a structure Employee that contains another
structure Date (to store the joining date). Accept and display employee details.
4. Write a C program to read a file containing student records (Name, Roll No, Marks) and display students
who scored more than 75 marks.

5. Write a C program that takes user input (Name, Age, City) and writes it to a file in append mode. The
program should then read the file and display its contents.

6. Write a program to open, write, read, append and close a file.[10

7. Write a program to use dynamic memory allocation on for an array using all the functions for dynamic
memory allocation on in C from standard library.

8. Explain structure within a structure and array of structures with examples and also elaborate differences
within the two. [6+4]

You might also like