Programming Questions
Practice Programming MCQs with answers and explanations. Page 2 of 6.
Category
Technical Questions
Topic
Programming
Page
2 / 6
Mode
Practice
Questions
Open any question to view the answer and explanation.
In the following C program that uses a do-while loop, how many times is the value of i checked in the loop condition?
#include <stdio.h>
int main()
{
int i = 0;
do
{
i++;
printf("In while loop\
");
} while (i < 3);
return 0;
}
Open
View answer
In the following C program, what will be printed for the sizes of the pointer variables better and best (assume a 32-bit system)?
#include <stdio.h>
void main()
{
char good, *better, *best;
printf("%d..%d", sizeof(better), sizeof(best));
}
Open
View answer
In the following C program that uses a goto label defined in a different function, what happens when you try to compile it?
#include <stdio.h>
void fun(void)
{
here:
printf("PP");
}
int main(void)
{
int i = 1;
while (i <= 5)
{
printf("%d", i);
if (i > 2)
goto here;
i++;
}
return 0;
}
Open
View answer
In an object oriented language such as Java or C#, for a declaration and call like x = Circle(), which statement about x is most accurate?
Open
View answer
In C programming, what is the output of this code that evaluates an expression with the modulus, multiplication and division operators?
#include <stdio.h>
void main()
{
int y = 3;
int x = 5 % 2 * 3 / 2;
printf("Value of x is %d", x);
}
Open
View answer
In C programming, what is the output of this code that uses the left shift operator on an integer?
#include <stdio.h>
void main()
{
int x = 1, z = 3;
int y = x << 3;
printf("%d\
", y);
}
Open
View answer
In the following C program, what happens when you attempt to modify a const int object through a non const pointer?
#include <stdio.h>
int main(void)
{
const int x = 5;
int *ptrx;
ptrx = &x; /* attempt to assign address of const int to non const pointer */
*ptrx = 10;
printf("%d", x);
return 0;
}
Open
View answer
In the following C program using a const pointer to char, where does the error occur and why?
#include <stdio.h>
int main(void)
{
char mybuf[] = "Zanzibar";
char yourbuf[] = " Zienckewiz";
char * const ptr = mybuf;
*ptr = 'a';
ptr = yourbuf;
return 0;
}
Open
View answer
In C programming, what operations are performed by the library style functions atoi(), itoa() and gcvt() when converting between strings and numeric values?
Open
View answer
In C and related environments, what is the difference in purpose between the functions rand(), random(), srand() and randomize() when working with pseudo random numbers?
Open
View answer
In C programming, what will be the output when you execute the following code that mixes switch case labels with goto?
#include <stdio.h>
void main()
{
switch (2)
{
case 1L:
printf("No");
case 2L:
printf("%s", "I");
goto Love;
case 3L:
printf("Please");
case 4L:
Love:
printf("Hi");
}
}
Open
View answer
In algorithm design, which of the following best describes what a simple linear search function written in C does when searching an array for a target value?
Open
View answer
In C programming, rewrite the following set of statements using the conditional (ternary) operator so that the behavior is preserved:
int a = 1, b;
if (a > 10)
b = 20;
Open
View answer
In C programming, consider the following recursive program:
main()
{
printf("Jamboree");
main();
}
How many times will the word Jamboree be printed?
Open
View answer
In software design and documentation, a macro flowchart is also known as which type of flowchart?
Open
View answer
Consider the following Java interface:
public abstract interface Frobnicate {
public void twiddle(String s);
}
Which of the following Frob class declarations is correct with respect to this interface?
Open
View answer
In expression conversion, convert the following infix expression to its equivalent prefix notation:
((A + B) * C – (D – E) ^ (F + G))
Open
View answer
In C and POSIX style systems, what value does the low level read function return when it reaches the end of a file during a read operation?
Open
View answer
In the following C program that uses function pointers and console functions, what output is produced on the screen?
#include <stdio.h>
#include <conio.h>
int main()
{
void (*p)();
int (*q)();
int (*r)();
p = clrscr;
q = getch;
r = puts;
(*p)();
(*r)("www.curioustab.com");
(*q)();
return 0;
}
Open
View answer
In C programming, consider the following code:
main()
{
char a[] = "Visual C++";
char *b = "Visual C++";
printf("
%d %d", sizeof(a), sizeof(b));
printf("
%d %d", sizeof(*a), sizeof(*b));
}
What values are printed by the two printf calls on a typical 32 bit system where char pointers are 4 bytes?
Open
View answer
Practice smarter
Solve a few questions daily and revisit weak topics regularly to improve accuracy.