Programming Questions
Practice Programming MCQs with answers and explanations. Page 5 of 6.
Category
Technical Questions
Topic
Programming
Page
5 / 6
Mode
Practice
Questions
Open any question to view the answer and explanation.
In C, consider the call printf("%d", num); where num is of type long int. Why is the compiler often not required by the language standard to issue a type mismatch warning for this call, even though the format string expects an int?
Open
View answer
In C, how would you use the standard library function qsort() to sort an array of structures struct student arr[N] in ascending order of the marks field?
Open
View answer
In C, what will be the output of the following program that combines a for loop, a while loop, a do while loop and the continue statement?
#include <stdio.h>
int main(void) {
int i;
for (i = 10; i <= 15; i++) {
while (i) {
do {
printf("%d ", 1);
if (i > 1)
continue;
} while (0);
break;
}
}
return 0;
}
Open
View answer
In the following C code that declares an enum and uses a switch statement, what output will be produced when the program is executed?
#include <stdio.h>
enum actor {
SeanPenn = 5,
AlPacino = -2,
GaryOldman,
EdNorton
};
int main(void) {
enum actor a = 0;
switch (a) {
case SeanPenn: printf("Kevin Spacey"); break;
case AlPacino: printf("Paul Giamatti"); break;
case GaryOldman: printf("Donald Shuterland"); break;
case EdNorton: printf("Johnny Depp"); break;
}
return 0;
}
Open
View answer
In C, which of the following small programs best implements a simplified version of the DOS type command that prints the contents of a text file specified on the command line to standard output?
Open
View answer
In C control flow, why and when would you choose a do while loop instead of a while loop for a particular piece of logic?
Open
View answer
In C, which of the following code snippets correctly swaps the values of two integer variables a and b without using a third temporary variable, while avoiding undefined behaviour for distinct variables?
Open
View answer
In C programming, which of the following code fragments correctly generates and prints the first n terms of the Fibonacci series, starting with 0 and 1, where n is read from the user?
Open
View answer
In C programming, which of the following functions correctly computes the factorial of a non negative integer n using an iterative approach and returns the result as a long long?
Open
View answer
In C, a strong number is a number whose value equals the sum of the factorials of its digits (for example 145 = 1! + 4! + 5!). Which of the following code fragments correctly checks whether an integer n is a strong number and prints an appropriate message?
Open
View answer
In C, which of the following code snippets correctly prints the multiplication table of an integer n from 1 × n up to 10 × n after reading n from the user?
Open
View answer
In C programming, how does the selection sort algorithm arrange an array of n elements in ascending order?
Open
View answer
In C programming, which statement best describes how the quick sort algorithm sorts an array in ascending order?
Open
View answer
In C programming, how does the insertion sort algorithm build a sorted array from an unsorted array?
Open
View answer
In C programming, which description correctly explains how the merge sort algorithm works?
Open
View answer
In C programming, what is the key idea behind the iterative binary search algorithm on a sorted array?
Open
View answer
In C programming, what does a standard matrix multiplication program compute when multiplying an m x n matrix A by an n x p matrix B?
Open
View answer
In C programming using standard library functions, what does a typical file copy program do when copying data from one file to another?
Open
View answer
In the following C program using nested structures, what output is produced on a typical system?
struct India {
char c;
float d;
};
struct World {
int a[3];
char b;
struct India orissa;
};
int main() {
struct World st = { {1, 2, 3}, 'P', {'q', 1.4f} };
printf("%d\t%c\t%c\t%f", st.a[1], st.b, st.orissa.c, st.orissa.d);
return 0;
}
Open
View answer
What is the output of the following C program?
void m() {
printf("hi");
}
int main() {
m();
return 0;
}
Open
View answer
Practice smarter
Solve a few questions daily and revisit weak topics regularly to improve accuracy.