# Recent questions in Programming and DS

1
A stack based CPU executes the instruction. Memory location $500$ contain $0X 88$ and memory location $700$ contain $0X37$. The stack pointer is at $0X003F$ The instruction are as follows: $I_{1}:PUSH$ $500$ $I_{2}:PUSH$. $700$ $I_{3}:ADD$ $I_{4}:POP$ ... $0X88$ after execution of instruction. $C)$ Memory location $600$ contain $0XBF$ after execution of instruction. $D)$ Both $a)$ and $c)$
2
https://gateoverflow.in/?qa=blob&qa_blobid=14433986388826671915 int main() { int a = 10; int *b = &a; scanf("%d",b); printf("%d",a+50); } What will be the Output of the following code if input given is $25$ ?
3
#include<stdio.h> #include<iostream> int bar(int m, int n){ if(m==0)return n; if(n==0)return m; return bar(n%m,m); } int foo(int m,int n){ return(m*n/bar(m,n)); } int main(){ int x=foo(1000,1500); printf("%d",x); return 0; } Output of the program is ___________
4
Consider the following $C$ implementation which when given $3$ numbers a,b,c as input, find the maximum of $3$ numbers $a,b,c.$ int kickstart(int a,int b,int c) { if(B1) return a; if(a>=b) return B2; return kickstart(c,a,b); } How the boxes filled up correctly? $I)B1:a\geq b$ ... $IV)B1:a\geq b$ && $a\geq c, B2:kickstart\left ( b,c,a \right );$ Is it $I) and II)$ or $I) and IV)$
1 vote
5
6
A default catch block catches, [A]. all thrown objects [B]. no thrown objects [C]. any thrown object that has not been caught by an earlier catch block [D]. all thrown objects that have been caught by an earlier catch block
7
What will be the output of the below code? the answer given is E)0 but I am not getting it. #include <stdio.h> void fun(short int *a,char *b) { b += 2; short int *p = (short int*)b; *p = *a; } int main() { void (*fptr)(short int *,char *) short int a = 101; char ... *fptr)(&a,arr); printf("%d", arr[3]); return 0; } $A)$ Compilation error. $B) 100$ $C)$ Garbage Value $D)$ Segmentation Fault. $E) 0$
8
Can someone explain the output of this code? and what (char*) is doing actually? #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; }
9
Consider the following function $foo()$ void foo(int n){ if(n<=0) printf("Bye"); else{ printf("Hi"); foo(n-3); printf("Hi"); foo(n-1); } } Let $P(n)$ represent recurrence relation, indicating number of time print statement executed. What will best recurrence for ... $n=0$ The options are confusing to me. Can someone explain the options well. Moreover , what will be constant added $1$ or $2?$
1 vote
10
Consider the following C code: int getNextGap(int gap){ gap=(gap*10)/13; if(gap<1)return 1; return gap; } void mystery(int a[ ],int n){ int gap=n; bool red=true; while(gap!=1||red==true){ gap=getNextGap(gap); red=false; for(int i=0;i<(n-gap ... n is number of array elements, then what output will print at last? I mostly stuck how bool function working here. Plz help me out, how program executing:(
1 vote
11
Consider the following function int fun(int a[ ],int l, int target){ int i=0,j=0,sum=0,count=0; while(j<l){ if(sum<target){ sum=sum+a[j]; j++; } else if(sum>target){ sum=sum-a[i]; i++; } else{ count++; sum=sum-a[i]; i++; } } if(sum==target) ... be return value of function call $fun\left ( a,16,8 \right )=$_______________ Given ans $6,$ but I got $4.$ Which one correct?? Any shortcut to evaluate??
1 vote
12
#include<stdio.h> int main(){ int (*a)[5]; int arr[5][5]={ {10,65,300,400,500}, {100,20,3000,40,5000} }; a = arr; ++a ; char *ptr = (char*)*a; ++a ; printf("%d %d %d",**a,*arr[1],*ptr); return 0; }
13
Can someone tell me, why these two same program giving different output?Is there any problem in code or compiler not producing right? Program1 Program2
1 vote
14
There is given a infix expression: ${\color{Red} {1}}$ $A+B\times C/\left ( \left ( D+E \right )+F\times G \right )$ While converting infix expression to postfix expression number of symbols in the stack at indicated ${\color{Red} {point-1}}$ infix expression (assume stack is initially empty) ______________ they told $5$, but is it correct? Can anyone give some explanation??
1 vote
15
$1)$ How to access array element with array of pointers? By pointer to an array we can access like this $(*a)[0]$,$(*a)[22]$, .. like this right? but how with array of pointer? $2)$Check these three codes , one of them use array and one of them use array of pointer, and 3rd one ... **ptr[12]; int main(void) { if(*(ptr+5)==*(ptr+3)){ printf("Equal"); } else{ printf("Not Equal"); } return 0; }
16
Consider a hash table with $N$ slots. It is given that the collision resolution technique used in chaining. Assume simple uniform hashing, what is the probability that the last $k$ slots are unfilled after the first $’r’$ insertions? $A)\left ( 1-\frac{N}{k} \right )^{r}$ $B)\left ( 1-\frac{k}{N} \right )^{r}$ $C)\left ( 1+\frac{N}{k} \right )^{r-1}$ $D)\left ( 1-\frac{k}{N} \right )^{r-1}$
17
#include<stdio.h> #include<string.h> int main(void) { char *a="MADEEASY"; char *b="GATECSIT2019"; char *r=a; char *s=b; printf("%d",(int)strlen(b+3[r]-1[s])); return 0; } Ans is given $8.$ I know basic thing, but couldnot getting what strlen(b+3[r]-1[s]) returning?? Plz explain.
Consider the following program: void A(int n){ printf("*"); if(n>1){ A(n/4); A(n/4); A(n/4); A(n/4); } } Let $X$ be number of asterisks printed by above function when $n=1024.$ Then the value of $X$ will be ____________ How ans will be $\frac{4^{k+1}-1}{3}$ , where $k=5?$ .
Consider the integer array $A\left [ 1.........100,1.......100 \right ]$ in which the elements are stored in $Z$ representation. An example of a $5\times 5$ array in $Z$ representation is shown below: If the base address of $A$ is starting from $1000$ ... $A$ is stored in Row Major Order, then the address corresponding to $A\left [ 100 \right ]\left [ 55 \right ]$ is ________________