Hard Qus
Hard Qus
1. Explain the difference between primitive and non-primitive data types. Provide
examples.
2. What is type casting, and how does it work in programming? Give an example of
implicit and explicit casting.
3. Describe the memory layout for a structure that contains an int, float, and
char. How does padding affect the layout?
4. What is the range of values for a signed 16-bit integer? How does this differ
from an unsigned 16-bit integer?
5. Discuss the significance of the void data type in functions. What does it
indicate about the function's return value?
Variables
1. What is the difference between global and local variables? Provide a code
example illustrating both.
2. How do variable scopes affect the accessibility of variables in nested
functions?
3. Explain the concept of variable lifetime in programming. What happens to local
variables when a function exits?
4. Describe the initialization of variables. What is the difference between static
and dynamic initialization?
5. What is a constant variable? How can it be declared in a programming language
of your choice?
Operators
1. Explain the difference between unary and binary operators with examples.
2. What are bitwise operators? Provide an example of how they can be used to
manipulate individual bits in an integer.
3. Discuss the role of the ternary operator. Write a code snippet that
demonstrates its use.
4. What is the significance of operator precedence in complex expressions? How do
parentheses affect it?
5. Describe how compound assignment operators work, giving examples of at least
three different types.
Conditional
1. Write a program that uses a switch-case statement to determine the grade based
on a given score.
2. How can you use nested if-else statements to evaluate multiple conditions?
Provide an example.
3. Discuss the short-circuit evaluation of logical operators. How does it impact
performance?
4. Explain the use of the else if construct. How does it differ from multiple if
statements?
5. Create a program that checks if a number is both even and positive using
conditional statements.
Loops
1. Compare and contrast for, while, and do-while loops. Provide an example where
each would be most appropriate.
2. Write a program that uses a loop to calculate the sum of all even numbers from
1 to 100.
3. How can you use a loop to create a multiplication table for a given number?
Provide a code snippet.
4. Describe how to use a loop to iterate over a string and count the number of
vowels.
5. Explain the use of nested loops. Write a code snippet that prints a 5x5
multiplication table.
Arrays
Strings
1. How do you concatenate two strings in your chosen programming language? Provide
a code example.
2. Write a function to check if a given string is a palindrome. Explain your
approach.
3. Describe how to find the length of a string without using built-in functions.
Provide a code snippet.
4. Explain how to compare two strings for equality. What factors should be
considered?
5. How can you convert a string to uppercase or lowercase? Write a code snippet
demonstrating this.
Enumerated Data Types
1. Define an enumerated type for the months of the year. Write a function that
prints the month name based on the enum value.
2. Explain how enumerated types can enhance code readability. Provide an example
of usage.
3. Write a code snippet that uses an enum to represent traffic light states and
uses a switch-case to display the corresponding action.
4. Discuss the underlying integer values assigned to enum constants. Can they be
changed?
5. How do enumerated types differ from constant variables? Provide examples.
Functions
Pointers
1. Explain what a pointer is and how it differs from a regular variable. Provide
an example of pointer usage.
2. Describe how to use pointers to dynamically allocate memory for an array.
Provide a code snippet.
3. What are dangling pointers, and how can they cause issues in programs? Discuss
prevention methods.
4. Explain pointer arithmetic with examples. How does incrementing a pointer
affect the memory address?
5. Write a function that swaps two integers using pointers. Explain how this works
in terms of memory.
File Handling
1. How do you open and close a file in your chosen programming language? Provide a
code snippet.
2. Write a program that reads a file line by line and counts the number of words
in it.
3. Discuss the different modes for opening a file (read, write, append). Provide
examples for each.
4. Explain how to handle errors during file operations. What techniques can be
used?
5. Write a function that writes an array of integers to a file and explain how to
format the output.
Comments
Binary Search
1. Explain the binary search algorithm and its time complexity. Under what
conditions can it be applied?
2. Write a binary search function for a sorted array of integers. Explain each
step of the algorithm.
3. Discuss how to determine the position of a target value in a sorted array using
binary search.
4. What are the advantages of binary search compared to linear search? Provide
scenarios where binary search is more efficient.
5. How can you modify the binary search algorithm to find the first occurrence of
a duplicate element?
Linear Search
1. Describe the linear search algorithm and its time complexity. In what scenarios
is it most useful?
2. Write a linear search function to find a specified element in an unsorted array
of integers. Explain your approach.
3. Compare linear search to binary search. When would you choose to use linear
search despite binary search's advantages?
4. Discuss how to implement linear search recursively. Provide a code snippet to
illustrate this.
5. Write a program that counts the number of times a specified element appears in
an array using linear search.
Bubble Sort
1. Explain how the bubble sort algorithm works and its time complexity in the best
and worst cases.
2. Write a bubble sort function that sorts an array of integers in ascending
order. Provide detailed comments.
3. Discuss the stability of bubble sort. What does it mean for a sorting algorithm
to be stable?
4. How can you optimize the bubble sort algorithm to stop early if the array is
already sorted?
5. Provide a code snippet that demonstrates the process of bubble sort step-by-
step for a given array.
Insertion Sort
1. Explain the insertion sort algorithm and its time complexity. In what scenarios
is it most efficient?
2. Write a function that implements insertion sort on an array of integers.
Explain each step of the process.
3. Discuss the advantages of insertion sort over other sorting algorithms,
especially for small datasets.
4. How can insertion sort be adapted to work with linked lists? Describe the
approach.
5. Provide a code example that illustrates how insertion sort builds a sorted
array incrementally.
Selection Sort
1. Describe the selection sort algorithm and its time complexity. Provide an
example of its operation on an array.
2. Write a selection sort function that sorts an array in descending order.
Include comments explaining your logic.
3. Discuss the concept of the "minimum" element in selection sort. How is it found
during each iteration?
4. Explain how selection sort performs in terms of memory usage compared to other
sorting algorithms.
5. Provide a step-by-step breakdown of how selection sort would sort the array
{64, 25, 12, 22, 11}.
1. Explain the difference between the break and continue statements with examples.
2. Write a loop that uses continue to skip all odd numbers while printing the
numbers from 1 to 20.
3. Describe how break can be used to exit a loop early. Provide a scenario where
this would be useful.
4. Write a program that demonstrates the use of both break and continue within
nested loops.
5. Discuss the impact of using break in switch-case statements. How does it change
control flow?
Feel free to ask for clarifications or additional questions on specific topics!