# Recent questions and answers in Programming

The correct answer is (b). I am not able to understand how it is the correct answer, please explain.
What is the output of program? void swap (char *x, char *y) { char *t = x; x = y; y = t; } int main() { char *x = "IGATE"; char *y = "BEST IN CG"; char *t; swap(x, y); printf("(%s, %s)", x, y); t = x; x = y; y = t; printf("\n(%s, %s)", x, y); return ... CG, IGATE) . B: (BEST IN CG, IGATE) (IGATE, BEST IN CG) . C: (IGATE, BEST IN CG) (IGATE, BEST IN CG). D: (BEST IN CG, IGATE) (BEST IN CG, IGATE).
The value of k at the end of the execution of following program: int increase(int p) { int amount = 0; amount = amount +p; return(amount); } main( ) { int i, j, k; for(i = 0: i < 4; i++) { for( j = 0: j <=i; j++) { k = increase(j); } } } A) 4 B) 10 C) 20 D) 6
Consider the following C function: void f(int m) { while (m! = 0) { if(!(m &1)) printf("hello"); m = m >> 1; } } The number of times printf("hello") statement is executed, when 2048 is passed to the function ()
which of the following is/are illegal after the following declaration int A[10],B[20],*C; A) A=B B) B=A C) A= C D) C=A
1 vote
What does the following function declare int *(*p)(char (*a) []); A)p is a pointer to a function that takes an argument as pointer and returns an integer. B) p is a pointer to a function takes an argument as pointer to a character and returns a pointer ... a pointer to a function that takes an argument as array of pointers to characters and returns a pointer to an integer. D) None of these.
Which rule of recursion is violated in the following code int rec(int n) { if(n == 0) return 0; else return (n + rec(n/2) +rec(n/2+ 1); } A) No base case B ) Fails to make progress C) It performs redundant work D) No violation
Write a C macro without using any conditional checks to set or reset a particular bit in a variable based on the third argument. SETRESET (variable, bitposition, set/reset) Could you help me with this??
"In Binary tree, for every node the difference between the number of nodes in the left and right subtrees is at most 2." How is this statement valid in case of Left or Right Skewed Binary tree?
#include <iostream> using namespace std; int main() { int a[3][4][2] = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20}; printf("%d", *((*(a+2)-3))[2]); return 0; } How the output of this code coming out to be 15. Can someone please explain this?
Is Space Also Allocated In Memory For Other Literal Constants(int/char/float Etc)? Because For String Literal Constants Memory Is Allocated.
1 vote
https://www.onlinegdb.com/edit/r1CBB9EHO #include<stdio.h> int main() { short int i = 10; char c = 'a'; float p = 3.0; short int s = i+c; printf("%d\n", sizeof(short int)); //size of short int is 2 printf("%d\n", sizeof(char)); // size of char is 1 printf(" ... + short int) should be short int whose size should be 2. */ printf("%d", sizeof(s)); // though here it is 2 which is correct. return 0; }
please explain the difference in extern and global variable both have global scope then what is the difference how they used as in programme
function mu(a,b:integer) returns integer; var i,y: integer; begin ---------P---------- i = 0; y = 0; while (i < a) do begin --------Q------------ y := y + b ; i = i + 1 end return y end I arrived at the answer that Q=y<a P=y<i
1 vote
Please explain how to get the outputs here? void main() { int i=255, j; char *p; p=&i; j=*p; *p=32; printf("%d %d",i,j); } void main() { int i=265, j; char *p; p=&i; j=*p; *p=32; printf("%d %d",i,j); }
#include<stdio.h> int main() { char *s[] = { "knowledge","is","power"}; char **p; p = s; printf("%s ", ++*p); printf("%s ", *p++); printf("%s ", ++*p); return 0; }
#include <stdio.h> #define VAL 32 int main() { char arr[] = "geeksquiz"; *(arr + 0) &= ~VAL; *(arr + 5) &= ~VAL; printf("%s", arr); return 0; }
Consider the following $\text{ANSI C}$ program. #include <stdio.h> int main() { int arr[4][5]; int i, j; for (i=0; i<4; i++) ​​​​​​{ for (j=0; j<5; j++) { arr[i][j] = 10 * i + j; } } printf(“%d”, *(arr[1]+9)); return 0; } What is the output of the above program? $14$ $20$ $24$ $30$
Consider the following $\text{ANSI C}$ program: #include <stdio.h> #include <stdlib.h> struct Node{ int value; struct Node *next;}; int main( ) { struct Node *boxE, *head, *boxN; int index=0; boxE=head= (struct Node *) malloc(sizeof(struct Node)) ... $\textsf{return}$ which will be reported as an error by the compiler It dereferences an uninitialized pointer that may result in a run-time error
1 vote
Consider the following$\text{ ANSI C}$ program. #include <stdio.h> int main() { int i, j, count; count=0; i=0; for (j=-3; j<=3; j++) { if (( j >= 0) && (i++)) count = count + j; } count = count + ... will compile successfully and output $10$ when executed The program will compile successfully and output $8$ when executed The program will compile successfully and output $13$ when executed
Number of sorting algorithms given below that has a time complexity of O(n^2) : Selection sort Merge sort Bubble sort Quick sort Answer for this should be 3, but in made easy test solution they have given answer as 4, can time complexity of merge sort be O(n^2) ??
#Self Doubt When Space complexity is asked in GATE exam , should we consider only the extra space ( auxiliary space ) that is needed or both the extra space & space required for input As per my understanding we need to take only extra but in Geek For Geeks / other ... both.Belowe is the link Link: https://www.geeksforgeeks.org/g-fact-86/amp/ Please confirm with respect to gate exam point of view.
" if we assume uniform hashing, what is the probability that a collision will occur in a hash table with 100 buckets and 2 keys?" Doesn't this question means that we have a hash table in which there are already 2 keys, and we have to find probability of collision for the next insertion? Or it is asking the probability of collision in the table for these two keys insertion?
In the question number mentioned above, I had a doubt that what will happen if *px = INT_MIN and *py = INT_MAX. Because if we do *px = *px – *py, then ideally *px will become less than INT_MIN which will not be possible to store in int data type, and hence may give unexpected results, so according to me S4 should also be correct
https://gateoverflow.in/19251/tifr2010-b-37 by counter example like for a= 2 and b =1 the loop does not terminate thus remaining options are A and D. But I'm having problem getting D as answer my answer is A as at any random example say a = 4 and b =2 we get final ... evidently z != a*b , so I go with Option A. considering this comment of the.brahmin.guy how it is not terminating using a=2 nd b
1 vote
"Consider the following array of elements <40, 35, 20, 10, 15, 16, 17, 8, 4, 30>. The minimum number of interchanges needed to convert it into a min-heap is _________ using built heap method." I am getting 7.
The number of min heap trees are possible with 15 distinct elements such that every leaf node must be greater than all non-leaf nodes of the tree are ________. According to me, the answer should be 80* 8! The given answer is different.
#include<stdio.h> struct Ournode{ char x, y, z; }; int main() { struct Ournode p={'1', '0', 'a'+2}; struct Ournode *q=&p; printf("%c, %c", *((char*)q+1), *((char*)q+2)); return 0; } In this question the size of p is 3 byte and q is pointing to p so when we are doig to q+1 why it is not pointing to location p+3
Code: #include <stdio.h> #define TOTAL_ELEMENTS(sizeof(array))/sizeof(array[0]) int array[ ]={23,34,17,204,99,16}; int main() { int d; printf("%d",TOTAL_ELEMENTS); for (d=-1;d<=(TOTAL_ELEMENTS - 2);d++) printf ("%d",array[d+1]); return 0; } What is the output of the above code?
Q. What does the following program do when the input is unsigned 16-bit integer? #include<stdio.h> main() { unsigned int num; int i; scanf("%u",&num); for(i=0;i<16;i++) { printf("%d.",(num << i&1 <<15)?1:0); } } (A) it prints all even bits from num (B) it prints all odd bits from num (C) it prints binary equivalent of num (D) none of the above
Q. What does the following program do when the input is unsigned 16-bit integer? #include<stdio.h> main() { unsigned int num; int i; scanf("%u",&num); for(i=0;i<16;i++) { printf("%d.",(num << i&1 <<15)?1:0); } } (A) it prints all even bits from num (B) it prints all odd bits from num (C) it prints binary equivalent of num (D) none of the above
1 vote
For the code: int z,x=5,y=-10,a=4,b=2; z=x++---y*b/a; The value of z will be_______
void main() { int x = 0; if(0 && ++x) x++; printf("%d\n", x); }
Draw the AVL tree after each of the following inserts in succession, i.e., one after the other. Note: Show only the perfect (by rotating nodes) tree after each insertion. 1. insert(15) 2. insert(17) 3. insert(18) 4. insert(21) 5. insert(23) 6. insert(25) 7. insert(31) 8. insert(38) 9. insert(34) 10. insert(40) (Only draw tree,no need to code )
1 vote
What does the following C-statement declare? int (*f) (int * ); A function that takes an integer pointer as argument and returns an integer A function that takes an integer as argument and returns an integer pointer A pointer to a function that takes an integer pointer as argument and returns an integer A function that takes an integer pointer as argument and returns a function pointer
1 vote
Consider the following function implemented in C: void printxy(int x, int y) { int *ptr; x=0; ptr=&x; y=*ptr; *ptr=1; printf(“%d, %d”, x, y); } The output of invoking $printxy(1,1)$ is: $0, 0$ $0, 1$ $1, 0$ $1, 1$
What does the following program print? #include<stdio.h> void f(int *p, int *q) { p=q; *p=2; } int i=0, j=1; int main() { f(&i, &j); printf("%d %d\n", i,j); return 0; } $2 \ 2$ $2 \ 1$ $0 \ 1$ $0 \ 2$