Programming Questions

Practice Programming MCQs with answers and explanations. Page 3 of 6.

Category
Technical Questions
Topic
Programming
Page
3 / 6
Mode
Practice

Questions

Open any question to view the answer and explanation.

In the following C program, an array of character pointers is declared: main() { char *str[] = { "Frogs", "Do", "Not", "Die", "They", "Croak!" }; printf("%d %d", sizeof(str), sizeof(str[0])); } How can you compute how many strings are stored in the array str?
Open
View answer
Point out the error, if any, in the following C program that reads characters from a file: #include "stdio.h" int main() { unsigned char; FILE *fp; fp = fopen("trail", "r"); while ((ch = getc(fp)) != EOF) printf("%c", ch); fclose(fp); return 0; }
Open
View answer
In the following C program that uses variable arguments, what is the main error? #include "stdarg.h" int main() { display(4, 12.5, 13.5, 14.5, 44.3); return 0; } void display(int num, ...) { float c; int j; va_list ptr; va_start(ptr, num); for (j = 1; j <= num; j++) { c = va_arg(ptr, float); printf(" %f", c); } }
Open
View answer
In legacy 16-bit C compilers that support near, far and huge pointer types, consider the following program: #include &lt;stdio.h&gt; int main() { char huge * near * far *ptr1; char near * far * huge *ptr2; char far * huge * near *ptr3; printf("%d %d %d", sizeof(ptr1), sizeof(ptr2), sizeof(ptr3)); return 0; } Assuming a memory model where far and huge pointers are 4 bytes and near pointers are 2 bytes, what is the output?
Open
View answer
In C programming, what is memmove used for and how should it be applied correctly?
Open
View answer
Consider the following C program: #include &lt;stdio.h&gt; int main() { int a = 10; void *p = &a; int *ptr = p; printf("%u", *ptr); return 0; } What output does this program produce on a typical system where int is 4 bytes?
Open
View answer
Consider the following C program: #include &lt;stdio.h&gt; struct student { int roll; int cgpa; int sgpa[8]; }; int main() { struct student s = { 12, 8, 7, 2, 5, 9 }; int *ptr; ptr = (int *)&s; printf("%d", *(ptr + 3)); return 0; } What value is printed by this program on a typical system where int values are stored consecutively without padding between struct members?
Open
View answer
In C programming, what is a simple and common way to check whether a given integer number is a palindrome?
Open
View answer
In C programming, to compute the sum of the main diagonal elements of a square matrix stored as a two dimensional array, which of the following approaches is correct?
Open
View answer
Consider the following C program that uses a goto inside a for loop: #include &lt;stdio.h&gt; int main() { int i = 0, k; if (i == 0) goto label; for (k = 0; k &lt; 3; k++) { printf("hi "); label: k = printf("%03d", i); } return 0; } What does this program print on the screen?
Open
View answer
In C, how can you rewrite the following conditional expression so that the constant 30 appears only once? a &lt;= 20 ? b = 30 : c = 30;
Open
View answer
Consider the following C program: #include &lt;stdio.h&gt; int main() { int i = -3, j = 2, k = 0, m; m = ++j && ++i || ++k; printf("%d %d %d %d", i, j, k, m); return 0; } What values are printed for i, j, k and m?
Open
View answer
In C programming, we want to round off x (a float variable) to an int value. Which of the following expressions correctly rounds x to the nearest integer value and then converts it to int?
Open
View answer
In C programming, consider the following macro and program. What would be the output? #define SQR(x) (x * x) int main() { int a, b = 3; a = SQR(b + 2); printf("%d", a); } Assume standard operator precedence and that printf is correctly declared.
Open
View answer
In enterprise job scheduling and batch processing, what is Autosys and what is it primarily used for?
Open
View answer
In the analysis of algorithms and data structures, what are the two main measures used to evaluate the efficiency of an algorithm?
Open
View answer
In a typical programming language (for example, Python), what is the result of evaluating math.floor(3.6)? Assume math has been imported and floor returns the greatest integer less than or equal to its argument.
Open
View answer
In C programming, consider the following code: #include <stdio.h> int main(void) { int x = 97; char y = x; printf("%c\ ", y); return 0; } What will this program print on a typical ASCII-based system?
Open
View answer
In Java programming, which of the following statements about the use of assertions is correct according to standard Java guidelines?
Open
View answer
In Java, methods declared with which keyword cannot be overridden in a subclass?
Open
View answer

Practice smarter

Solve a few questions daily and revisit weak topics regularly to improve accuracy.