# Recent questions and answers in Programming 0 votes
0 answers 9 views
The correct answer is (b). I am not able to understand how it is the correct answer, please explain.
0 votes
0 answers 5 views
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).
0 votes
1 answer 9 views
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
0 votes
0 answers 2 views
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 ()
0 votes
0 answers 5 views
which of the following is/are illegal after the following declaration int A,B,*C; A) A=B B) B=A C) A= C D) C=A
1 vote
1 answer 23 views
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.
0 votes
0 answers 13 views
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
0 votes
0 answers 7 views
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??
0 votes
0 answers 10 views
"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?
0 votes
0 answers 15 views
#include <iostream> using namespace std; int main() { int a = {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))); return 0; } How the output of this code coming out to be 15. Can someone please explain this?
0 votes
0 answers 17 views
Is Space Also Allocated In Memory For Other Literal Constants(int/char/float Etc)? Because For String Literal Constants Memory Is Allocated.
1 vote
1 answer 29 views
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; }
0 votes
0 answers 17 views
please explain the difference in extern and global variable both have global scope then what is the difference how they used as in programme
0 votes
0 answers 41 views
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
1 answer 46 views
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); }
0 votes
0 answers 37 views
#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; }
0 votes
0 answers 23 views
#include <stdio.h> #define VAL 32 int main() { char arr[] = "geeksquiz"; *(arr + 0) &= ~VAL; *(arr + 5) &= ~VAL; printf("%s", arr); return 0; }
3 votes
5 answers 1.5K views
Consider the following $\text{ANSI C}$ program. #include <stdio.h> int main() { int arr; int i, j; for (i=0; i<4; i++) ​​​​​​{ for (j=0; j<5; j++) { arr[i][j] = 10 * i + j; } } printf(“%d”, *(arr+9)); return 0; } What is the output of the above program? $14$ $20$ $24$ $30$
0 votes
2 answers 732 views
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
2 answers 604 views
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
0 votes
0 answers 29 views
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) ??
0 votes
0 answers 20 views
#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.
0 votes
0 answers 18 views
" 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?
0 votes
1 answer 37 views
0 votes
0 answers 30 views
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
0 votes
0 answers 20 views
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
0 answers 27 views
"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.
0 votes
0 answers 53 views
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.
2 votes
0 answers 41 views
#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
0 votes
1 answer 31 views
Code: #include <stdio.h> #define TOTAL_ELEMENTS(sizeof(array))/sizeof(array) 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?
0 votes
1 answer 18 views
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
0 votes
0 answers 17 views
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
1 answer 29 views
For the code: int z,x=5,y=-10,a=4,b=2; z=x++---y*b/a; The value of z will be_______
0 votes
1 answer 35 views
void main() { int x = 0; if(0 && ++x) x++; printf("%d\n", x); }
0 votes
0 answers 19 views
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
1 answer 18 views
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
1 answer 27 views
Consider the following C program. # include <stdio.h> void mystery (int *ptra, int *ptrb) { int *temp; temp = ptrb; ptrb =ptra; ptra = temp; } int main () { int a = 2016, b=0, c= 4, d = 42; mystery (&a, &b); if (a < c) mystery (&c, &a); mystery (&a, &d); print f("%d\n", a); } The output of the program is _________.
0 votes
1 answer 15 views
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$
1 vote
1 answer 16 views
The value printed by the following program is _______. void f (int * p, int m) { m = m + 5; *p = *p + m; return; } void main () { int i=5, j=10; f (&i, j); print f ("%d", i+j); }
1 vote
1 answer 17 views
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$
To see more, click for all the questions in this category.