Curioustab
Aptitude
General Knowledge
Verbal Reasoning
Computer Science
Interview
Take Free Test
Aptitude
General Knowledge
Verbal Reasoning
Computer Science
Interview
Take Free Test
Programming Questions
In the context of 8086-style segmented memory addressing in C (for example, Turbo C on DOS), how can you obtain the segment and offset parts from a far pointer that holds the address of a memory location?
In C, consider the following program. Assume that the array arr begins at address 65486 in memory. int main(void) { int arr[] = {12, 14, 15, 23, 45}; printf("%u %u", arr, &arr); return 0; } What values will be printed, given that sizeof(int) is 2 bytes and the implementation prints addresses as unsigned integers?
In standard C (without compiler-specific extensions), consider the following code: int main(void) { int a = 10, *j; void *k; j = k = &a; j++; k++; printf("%u %u", j, k); return 0; } Would this program compile successfully, and why?
In a DOS/Turbo C style C program, you want to write the character 'A' directly to video memory at segment B800h, offset 0000h using a far pointer. The following code generates a warning: int main(void) { char far *scr; scr = 0xB8000000; *scr = 'A'; return 0; } How can you eliminate the warning while still assigning the correct far address?
In C, consider the following program compiled with a typical 16-bit compiler where char is 1 byte and int is 2 bytes: int main(void) { char ch = 'A'; printf("%d%d", sizeof(ch), sizeof('A')); return 0; } What will this program print?
In C, consider the following typedef declaration for a linked list node pointer: typedef struct { int data; NODEPTR link; } *NODEPTR; What is the error, if any, in this code?
In C, consider the following code that writes a structure to a file using fwrite: struct emp { char *n; int age; }; struct emp e = { "Sujay", 15 }; FILE *fp; /* assume fp is a valid file pointer opened in binary write mode */ fwrite(&e, sizeof(e), 1, fp); Can another program later call fread on this file to reliably reconstruct the same struct emp value, including the string "Sujay", using a single fread(&e, sizeof(e), 1, fp) call?
In C, consider the following program compiled on a typical system where string literals are stored in read-only memory: int main(void) { struct emp { char *n; int age; }; struct emp e1 = { "Dravid", 23 }; struct emp e2 = e1; strupr(e2.n); printf("\ %s", e1.n); return 0; } Assuming strupr converts characters of the string in place to uppercase, what will this program print if modifying string literals is (non-portably) allowed by the compiler?
In C programming, you have two structure variables of the same type. What is a safe and portable way to check whether the contents of these two structures are the same?
In C, consider the following program that attempts to read and print all lines from a text file: #include "stdio.h" int main(void) { FILE *fp; char str[80]; fp = fopen("trail", "r"); while (!feof(fp)) { fgets(str, 80, fp); puts(str); } fclose(fp); return 0; } What is the logical error, if any, in this code for reading the file?
In C, consider this program saved as sample.c: int main(int argc, char **argv) { argc = argc - (argc - 1); printf("%s", argv[argc - 1]); return 0; } Regardless of how many command-line arguments are supplied, what does this program print?
In C, consider the following program run from the command line as: myprog 1 2 3 The source code is: int main(int argc, char *argv[]) { int i, j = 0; for (i = 0; i < argc; i++) j = j + atoi(argv[i]); printf("%d", j); return 0; } What will this program print?
In C, what will be the output of the following program that uses an unsigned int and the bitwise NOT operator? main() { unsigned int a = 0xffff; /* hexadecimal constant */ ~a; printf("%x", a); }
In C bit manipulation, consider the following macros for treating a char array as a compact bit set: #define CHARSIZE 8 #define MASK(y) (1 << ((y) % CHARSIZE)) #define BITSLOT(y) ((y) / CHARSIZE) #define SET(x,y) ( (x)[BITSLOT(y)] |= MASK(y) ) #define TEST(x,y) ( (x)[BITSLOT(y)] & MASK(y) ) #define NUMSLOTS(n) (((n) + CHARSIZE - 1) / CHARSIZE) Using these macros, how would you (1) declare an array arr that can hold 50 bits, (2) switch on the 20th bit and (3) test whether the 40th bit is on?
In the following C code using an incomplete struct type and a typedef for a pointer, is it valid to introduce the typedef before the struct is fully defined, and can the pointer member next use that typedef? typedef struct employee *ptr; struct employee { char name[20]; int age; ptr next; };
In C, how can you improve the following linked node declaration and allocation code using typedef so that the type name is shorter and clearer? struct node { int data1; float data2; struct node *left; struct node *right; }; struct node *ptr; ptr = (struct node *) malloc(sizeof(struct node));
In C, how would you dynamically allocate a 2 dimensional array of integers with ROWS rows and COLS columns using pointers and malloc, so that you can access elements as arr[i][j]?
In the following C program, dynamic memory is allocated for a 2 dimensional array using a double pointer. How should you correctly free all allocated memory to avoid leaks? #include "alloc.h" #define MAXROW 3 #define MAXCOL 4 int main(void) { int **p; int i; p = (int **) malloc(MAXROW * sizeof(int *)); for (i = 0; i < MAXROW; i++) p[i] = (int *) malloc(MAXCOL * sizeof(int)); /* ... use p ... */ }
In C dynamic memory management, can you increase the size of a dynamically allocated array, and if yes, which standard library function is typically used and how should it be applied safely?
In C dynamic memory allocation, what is the main difference between malloc() and calloc() functions when allocating blocks from the heap?
Prev
1
…
3
4
5
6
Next