search
Log In

Recent questions and answers in Programming

2 votes
3 answers
1
Consider 3 dimensional Array A[90] [30] [40] stored in linear array in column major order. If the base address starts at 10. The location of A[20] [20] [30] is __________ . [Assume the first element is stored at A[1][1][1] and each element take 1 B].
answered Jan 15 in Programming bthebestSelf 8.4k views
22 votes
3 answers
2
Consider the program where $a, b$ are integers with $b > 0$. x:=a; y:=b; z:=0; while y > 0 do if odd (x) then z:= z + x; y:= y - 1; else y:= y % 2; x:= 2 * x; fi Invariant of the loop is a condition which is true before and after every ... will not terminate for some values of $a, b$ but when it does terminate, the condition $z = a * b$ will hold. The program will terminate with $z=a^{b}$
answered Jan 10 in Programming mayur lilhare 1.6k views
34 votes
6 answers
3
Consider the following C program segment. # include <stdio.h> int main() { char s1[7] = "1234", *p; p = s1 + 2; *p = '0'; printf("%s", s1); } What will be printed by the program? $12$ $120400$ $1204$ $1034$
answered Jan 9 in Programming val_pro20 6.1k views
5 votes
3 answers
4
1.Linear Probing suffers from both primary and secondary clustering. true or false? 2. Quadratic Probing suffers from both primary and secondary clustering. true or false?
answered Jan 7 in Programming swettt871 2.2k views
4 votes
4 answers
5
Indicate results of the following program if the language uses i)Static scope rule and ii) Dynamic scope rules (GATE-1989) var x,y:integer; procedure A(var z:integer); var x:integer; begin x:=1; B; z:=x; end; procedure B; begin x:=x+1; end; begin x:=5; A(y); write(y) end;
answered Jan 5 in Programming Pratham rathore 977 views
24 votes
5 answers
6
double foo(int n) { int i; double sum; if(n == 0) { return 1.0; } else { sum = 0.0; for(i = 0; i < n; i++) { sum += foo(i); } return sum; } } Suppose we modify the above function $foo()$ ... modification the time complexity for function $foo()$ is significantly reduced. The space complexity of the modified function would be: $O(1)$ $O(n)$ $O(n^2)$ $n!$
answered Jan 4 in Programming reboot 4.9k views
41 votes
5 answers
7
double foo(int n) { int i; double sum; if(n == 0) { return 1.0; } else { sum = 0.0; for(i = 0; i < n; i++) { sum += foo(i); } return sum; } } The space complexity of the above code is? $O(1)$ $O(n)$ $O(n!)$ $n^n$
answered Dec 24, 2020 in Programming ShivangiChauhan 10.1k views
31 votes
5 answers
8
Consider the following program: int f (int * p, int n) { if (n <= 1) return 0; else return max (f (p+1, n-1), p[0] - p[1]); } int main () { int a[] = {3, 5, 2, 6, 4}; print f(" %d", f(a, 5)); } Note: $max (x, y)$ returns the maximum of $x$ and $y$. The value printed by this program is ________.
answered Dec 23, 2020 in Programming StoneHeart 6.5k views
75 votes
9 answers
9
Consider the following C program. #include<stdio.h> #include<string.h> void printlength(char *s, char *t) { unsigned int c=0; int len = ((strlen(s) - strlen(t)) > c) ? strlen(s) : strlen(t); printf("%d\n", len); } void main() { char *x = "abc"; ... that $strlen$ is defined in $string.h$ as returning a value of type $size\_t$, which is an unsigned int. The output of the program is __________ .
answered Dec 23, 2020 in Programming StoneHeart 12.6k views
24 votes
13 answers
10
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$
answered Dec 23, 2020 in Programming StoneHeart 4.2k views
14 votes
4 answers
11
Consider the following function definition. void greet(int n) { if(n>0) { printf("hello"); greet(n-1); } printf("world"); } If you run greet(n) for some non-negative integer n, what would it print? n times "hello", followed by n+1 times "world" n times "hello", followed by n times "world" n times "helloworld" n+1 times "helloworld" n times "helloworld", followed by "world"
answered Dec 23, 2020 in Programming StoneHeart 1.2k views
27 votes
4 answers
12
Let $a$ be an array containing $n$ integers in increasing order. The following algorithm determines whether there are two distinct numbers in the array whose difference is a specified number $S > 0$. i = 0; j = 1; while (j < n ){ if (E) j++; else if (a[j] - a[i] == S) break; else i++; } if (j < n) printf ... expression for E. $a[j] - a[i] > S$ $a[j] - a[i] < S$ $a[i] - a[j] < S$ $a[i] - a[j] > S$
answered Dec 23, 2020 in Programming StoneHeart 4.1k views
1 vote
1 answer
13
The height h of an AVL tree with n nodes lies in the interval: 1. log2(n+1) ≤ h < c log2(n+2)+b 2. log10(n) ≤ h < c log10(n+1)+b 3. log10(n+1) ≤ h < c log10(n+2)+b 4. log2(n) ≤ h < c log2(n+1)+b
answered Dec 17, 2020 in Programming shaktipratap 299 views
2 votes
1 answer
14
Consider an initially empty hash table of length 10. Following set of keys are inserted using open addressing with hash function h(k) = kmod 10 and linear probing. The number of different insertion sequence of the key values using the given hash function and linear probing will result ... to send the packet from source to destination with minimum number of hops. D) both b and c. I think it is B).
answered Dec 16, 2020 in Programming omzzz 377 views
21 votes
6 answers
15
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); }
answered Dec 14, 2020 in Programming varunrajarathnam 3.9k views
71 votes
8 answers
16
Consider the C functions foo and bar given below: int foo(int val) { int x=0; while(val > 0) { x = x + foo(val--); } return val; } int bar(int val) { int x = 0; while(val > 0) { x= x + bar(val-1); } ... $6$ and $6$ respectively. Infinite loop and abnormal termination respectively. Abnormal termination and infinite loop respectively. Both terminating abnormally.
answered Dec 11, 2020 in Programming varunrajarathnam 13k views
21 votes
4 answers
17
Consider the following C code. Assume that unsigned long int type length is $64$ bits. unsigned long int fun(unsigned long int n) { unsigned long int i, j=0, sum = 0; for( i=n; i>1; i=i/2) j++; for( ; j>1; j=j/2) sum++; return sum; } The value returned when we call fun with the input $2^{40}$ is: $4$ $5$ $6$ $40$
answered Dec 9, 2020 in Programming varunrajarathnam 6.8k views
31 votes
5 answers
18
#include<stdio.h> void fun1(char* s1, char* s2){ char* temp; temp = s1; s1 = s2; s2 = temp; } void fun2(char** s1, char** s2){ char* temp; temp = *s1; *s1 = *s2; *s2 = temp; } int main(){ char *str1="Hi", *str2 = "Bye"; fun1(str1, str2); printf("%s %s", str1, ... 0; } The output of the program above is: $\text{Hi Bye Bye Hi}$ $\text{Hi Bye Hi Bye}$ $\text{Bye Hi Hi Bye}$ $\text{Bye Hi Bye Hi}$
answered Dec 9, 2020 in Programming varunrajarathnam 7.5k views
28 votes
9 answers
19
Consider the following C program: #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; } The output of this program is: 0, c 0, a+2 '0', 'a+2' '0', 'c'
answered Dec 9, 2020 in Programming varunrajarathnam 9.5k views
17 votes
9 answers
20
Consider the following $\text{C}$ program: #include<stdio.h> int counter=0; int calc (int a, int b) { int c; counter++; if(b==3) return (a*a*a); else { c = calc(a, b/3); return (c*c*c); } } int main() { calc(4, 81); printf("%d", counter); } The output of this program is ______.
answered Dec 9, 2020 in Programming varunrajarathnam 5.1k views
32 votes
8 answers
21
Consider the following C program: double foo (double); /* Line 1 */ int main() { double da, db; //input da db = foo(da); } double foo (double a) { return a; } The above code compiled without any error or warning. ... compile warning or error some compiler-warnings not leading to unintended results some compiler-warnings due to type-mismatch eventually leading to unintended results compiler errors
answered Dec 9, 2020 in Programming Manu Shaurya 7.5k views
15 votes
5 answers
22
Consider the following psuedocode fragment, where $y$ is an integer that has been initialized. int i=1 int j=1 while (i<10): j=j*i i=i+1 if (i==y): break end if end while Consider the following statements: $(i==10)$ or $(i==y)$ If $y > 10$, then $i==10$ ... is/are TRUE at the end of the while loop? Choose from the following options. i only iii only ii and iii only i, ii, and iii None of the above
answered Dec 8, 2020 in Programming StoneHeart 1.3k views
8 votes
2 answers
23
Consider the following program fragment: var x, y: integer; x := 1; y := 0; while y < x do begin x := 2*x; y := y+1 end; For the above fragment , which of the following is a loop invariant ? $x=y+1$ $x=(y+1)^2$ $x=(y+1)2^y$ $x=2^y$ None of the above, since the loop does not terminate
answered Dec 8, 2020 in Programming StoneHeart 1.1k views
42 votes
6 answers
24
Consider the following program in C language: #include <stdio.h> main() { int i; int*pi = &i; scanf("%d",pi); printf("%d\n", i+5); } Which one of the following statements is TRUE? Compilation fails. Execution results in a run-time error. On execution, the value printed is $5$ more than the address of variable $i$. On execution, the value printed is $5$ more than the integer value entered.
answered Dec 8, 2020 in Programming StoneHeart 8k views
25 votes
6 answers
25
Consider the C program given below : #include <stdio.h> int main () { int sum = 0, maxsum = 0, i, n = 6; int a [] = {2, -2, -1, 3, 4, 2}; for (i = 0; i < n; i++) { if (i == 0 || a [i] < 0 || a [i] < a [i - 1]) { if (sum > maxsum) maxsum = sum ... sum += a [i]; } if (sum > maxsum) maxsum = sum ; printf ("%d\n", maxsum); } What is the value printed out when this program is executed? $9$ $8$ $7$ $6$
answered Dec 8, 2020 in Programming StoneHeart 5.3k views
42 votes
7 answers
26
The following$ C$ function takes two ASCII strings and determines whether one is an anagram of the other. An anagram of a string s is a string obtained by permuting the letters in s. int anagram (char *a, char *b) { int count [128], j; for (j = 0; j < 128; j++) count[j] = 0; j = 0; while (a[j] && b ... $A : count [a[j]]++ \ and \ B : count[b[j++]]--$
answered Dec 8, 2020 in Programming StoneHeart 6.5k views
7 votes
4 answers
27
Consider a 2D array with elemnts stored in the form of lower triangular matrix.The elements must be crossed to read A[4,2] from the array [-6..................+8 , -6..........+8 ] is
answered Dec 6, 2020 in Programming StoneHeart 3.1k views
1 vote
2 answers
28
Given that $x=7.5, j=-1.0, n=1.0, m=2.0$ the value of $--x+j==x>n>=m$ is: $0$ $1$ $2$ $3$
answered Nov 19, 2020 in Programming JashanArora 1.8k views
52 votes
5 answers
29
Consider this C code to swap two integers and these five statements: the code void swap (int *px, int *py) { *px = *px - *py; *py = *px + *py; *px = *py - *px; } S1: will generate a compilation error S2: may generate a segmentation fault at ... the swap procedure correctly for some but not all valid input pointers S5: may add or subtract integers and pointers S1 S2 and S3 S2 and S4 S2 and S5
answered Nov 14, 2020 in Programming Musa 9.8k views
10 votes
4 answers
30
Consider the following C functions. int tob (int b, int* arr) { int i; for (i = 0; b>0; i++) { if (b%2) arr [i] = 1; else arr[i] = 0; b = b/2; } return (i); } int pp(int a, int b) { int arr[20]; int i, tot = 1, ex, len; ex = a; len = tob(b, arr); for (i=0; i<len ; i++) { if (arr[i] ==1) tot = tot * ex; ex= ex*ex; } return (tot) ; } The value returned by $pp(3,4)$ is _______.
answered Nov 12, 2020 in Programming Asim Siddiqui 4 3.5k views
17 votes
5 answers
31
Consider the following C functions. int fun1(int n) { static int i= 0; if (n > 0) { ++i; fun1(n-1); } return (i); } int fun2(int n) { static int i= 0; if (n>0) { i = i+ fun1 (n) ; fun2(n-1) ; } return (i); } The return value of $\text{fun}2 (5)$ is _________
answered Nov 10, 2020 in Programming Asim Siddiqui 4 5.4k views
28 votes
9 answers
32
Aliasing in the context of programming languages refers to multiple variables having the same memory location multiple variables having the same value multiple variables having the same identifier multiple uses of the same variable
answered Oct 18, 2020 in Programming Pmona 5.7k views
3 votes
1 answer
33
Consider the following program fragment: int d = 0; int i,j,k; for(i=1; i<31; ++i) for(j=1; j<31; ++j) for(k=1; k<31; ++k) if(((i+j+k)%3) == 0) d=d+1; printf("%d",d); The number of additions performed by the above program fragment is? a. 27,000 b. 27,000 x 3 c. 27,000 x 3 + 9,000 d. 9,930 + 2,700 x 3
answered Oct 16, 2020 in Programming arun yadav 536 views
1 vote
3 answers
34
For n=2 the P is coming as 3,but none of the option is satisfying?
answered Oct 16, 2020 in Programming arun yadav 214 views
1 vote
2 answers
35
Consider the following program segment int main ( ) { char ∗ str = “GATECS”; printf (“%d”, madeeasy (str)); return 0; } int madeeasy (int ∗ p1) { int ∗ p2 = p1; while (∗++p1); return (p1 – p2); } The output of the above program will be ______. Assume that the object of data type int occupies 2 bytes
answered Oct 15, 2020 in Programming arun yadav 432 views
46 votes
8 answers
36
Consider the following pseudo code, where $x$ and $y$ are positive integers. begin q := 0 r := x while r ≥ y do begin r := r - y q := q + 1 end end The post condition that needs to be satisfied after the program terminates is $\{ r = qx + y \wedge r < y\}$ $\{ x = qy + r \wedge r < y\}$ $\{ y = qx + r \wedge 0 < r < y\}$ $\{ q + 1 < r - y \wedge y > 0\}$
answered Oct 13, 2020 in Programming Musa 7.6k views
16 votes
8 answers
37
1)The number of min heap trees are possible with 15 elements such that every leaf node must be greater than all non-leaf nodes of the tree are ________. -------------------------------------------------------------------------------------------------------------------------- 2)The number of min heap trees are possible with 15 elements_________________
answered Oct 6, 2020 in Programming StoneHeart 2.6k views
3 votes
1 answer
38
In the following procedure Integer procedure P(X,Y); Integer X,Y; value x; begin K=5; L=8; P=x+y; end $X$ is called by value and $Y$ is called by name. If the procedure were invoked by the following program fragment K=0; L=0; Z=P(K,L); then the value of $Z$ will be set equal to $5$ $8$ $13$ $0$
answered Sep 26, 2020 in Programming VIDYADHAR SHELKE 1 707 views
2 votes
0 answers
39
An external variable is globally accessible by all functions has a declaration “extern” associated with it when declared within a function will be initialized to $0$ if not initialized all of these
asked Apr 2, 2020 in Programming Lakshman Patel RJIT 236 views
1 vote
1 answer
40
If initialization is a part of declaration of a structure, then storage class can be automatic register static anything
asked Apr 2, 2020 in Programming Lakshman Patel RJIT 172 views
To see more, click for all the questions in this category.
...