Recent questions tagged array

7 7 votes
1 1 answer
341
341 views
A sequence of $n$ elements is implemented in two ways:As a normal array with contiguous memory and no extra empty slot. As a singly linked list with only a $\texttt{head}...
2 2 votes
3 3 answers
180
180 views
A function $\texttt{shuffle(s)}$ takes a sequence $\texttt{s}$ with an even number of elements. It returns a new list by interleaving the first half of $\texttt{s}$ with ...
2 2 votes
3 3 answers
149
149 views
Consider the following Python code:s = [3] s.extend([4, 5]) s.extend([s.append(9), s.append(10)]) print(s)What is the output of the code above?[3, 4, 5, 9, 10][3, 4, 5, N...
2 2 votes
3 3 answers
155
155 views
Consider the following Python code:s = [9, 7, 8] a, b = s, s[:] print(a is s, b == s, b is s) print(a.pop()) print(a + b)What is the output of the code above?True True Tr...
5 5 votes
2 2 answers
288
288 views
What is the output of the following code?#include <stdio.h struct Book { char name[4]; int pages; }; int main() { struct Book b1 = {"CAT", 50}; struct Book b2; b2 = b1; b...
5 5 votes
2 2 answers
296
296 views
What is the output of the following code?#include <stdio.h struct Student { int roll; int marks; }; int main() { struct Student s[3] = { {1, 70}, {2, 80}, {3, 90} }; s .m...
6 6 votes
1 1 answer
222
222 views
What is the output of the following code?#include <stdio.h int main() { char str[] = "CODE"; char *p = str; p++; *p = 'A'; printf("%s %c", str, *(p + 2)); return 0; }$\te...
6 6 votes
1 1 answer
200
200 views
What is the output of the following code?#include <stdio.h int main() { char str[] = "GATE"; char *p = str; printf("%c %c %s", str , *(p + 2), p + 1); return 0; }$\texttt...
6 6 votes
1 1 answer
185
185 views
What will happen when the following code is compiled?#include <stdio.h int main() { int a[] = {10, 20, 30}; a = a + 1; printf("%d", *a); return 0; }$\texttt{10}$ $\texttt...
5 5 votes
1 1 answer
182
182 views
Consider the following declarations:#include <stdio.h int main() { int a[4] = {6, 4, 1, 2}; int b[8] = {9, 8, 11, 10, 5, 7, 0, 3}; int *p = &a ; int *q = b; printf("%p", ...
7 7 votes
2 2 answers
229
229 views
What is the output of the following code?#include <stdio.h int main() { int a[] = {5, 10, 15, 20}; int *p = a + 1; printf("%d %d %td", *(p + 1), p , (p + 2) - a); return ...
8 8 votes
2 2 answers
262
262 views
What is the output of the following code?#include <stdio.h int main() { int a[] = {2, 4, 6, 8, 10}; int *p = a + 2; printf("%d %d %td", p[-1], 1[p], p - a); return 0; }$\...
7 7 votes
3 3 answers
232
232 views
What is the output of the following code?#include <stdio.h int main() { int a[4] = {6, 4, 1, 2}; int b[8] = {9, 8, 11, 10, 5, 7, 0, 3}; int *p = &a ; int *q = b; int *r =...
7 7 votes
2 2 answers
227
227 views
What is the output of the following code?#include <stdio.h int main() { int a[] = {3, 6, 9, 12, 15}; int *p = a + 1; printf("%d %d %td", *p, *(p + 2), p - a); return 0; }...
7 7 votes
2 2 answers
237
237 views
What is the output of the following code?#include <stdio.h int main() { int a[10] = {10, 11, 12, 13, 14, 15, 16, 17, 18, 19}; int *b = a + 4; int *c = &(a[4]); printf("%d...
7 7 votes
2 2 answers
278
278 views
What is the output of the following code?#include <stdio.h int main() { int a[] = {2, 4, 6, 8, 10}; printf("%d %d %d", *a, *(a + 3), 3[a]); return 0; }$\texttt{2 6 8}$ $\...
5 5 votes
2 2 answers
281
281 views
What is the output of the following code?#include <stdio.h int main() { int a[5] = {2, 4, 1, 3, 5}; int i, sum = 0; for (i = 0; i < 5; i++) { if (a[i] % 2 == 0) sum = sum...
2 2 votes
1 1 answer
597
597 views
Solution for above question Given : 1076My Solution: 1094My approch:PUSH 50 element from index 99, pos at 49.POP 8 elements, pos at 58.PUSH 10 elemnts, pos at 47.1000+47*...
5 5 votes
3 answers 3 answers
624
624 views
Should this question be invalid? t[4] Mentions 4 elements, but question assigns 5 elements.Because according to my knowledge accessing element t[4] (if we consider index ...
0 0 votes
1 1 answer
301
301 views
You were given an array of distinct elements of size n with indices starting from 0.-Every $(2i)^{th}$ element is pushed into a stack.-Every $(2i+1)^{th}$ element is enqu...
0 0 votes
0 0 answers
445
445 views
#include<stdio.h int main() { int a[] = {{1, 2},{ 3, 4}}; int i, j; int *p[] = { a, a+1, a+2}; for(i=0; i<2; i++) for(j=0; j<2; j++) printf("%d, %d, %d, %d\n", *(*(p+i)+...
1 1 vote
2 2 answers
525
525 views
What would be the equivalent pointer expression for referring the array element $\operatorname{ar}[\mathrm{m}][\mathrm{n}][\mathrm{o}]$$^* (^* (^* (\operatorname{ar})+\ma...
1 1 vote
2 2 answers
374
374 views
#include<stdio.h void main() { int arr[]={1, 2, 3, 4, 5}; int *p=arr; printf("%d", *p++); printf("%d", *(p+1)); }Find the output of the above code?$1,2$$1,3$$2,3$$1,4$
0 0 votes
1 1 answer
335
335 views
Consider following C program :#include<stdio.h int main() { int x[]={2,4,6,8,10}; int a, b=0, * y = x+4; for(a = 0; a<5; a++) { b=b+(*y -a) - *(y -a); } printf("%d\n", b)...
0 0 votes
1 1 answer
252
252 views
What will be the output of the following $\text{C}$ code?#include<stdio.h void main() { int arr[5]={10,20,30,40,50}; int *p = (int*) (&arr+1); printf("\%d\%d", *(arr + 1)...
0 0 votes
1 1 answer
332
332 views
Consider the following code segment:int arr [] = {0,1,2,3,4}; int i=1, *ptr; ptr = arr + 2;arrange the following printf statements in the increasing order of their output...
1 1 vote
1 1 answer
391
391 views
We have an array $A$ of $n$ numbers, where $n$ is a power of $2$.We build a full binary tree on top of the array $A.$ The elements of the array are leaves of the tree, nu...
1 1 vote
1 1 answer
292
292 views
We have an array $A$ of $n$ numbers, where $n$ is a power of $2$.We build a full binary tree on top of the array $A.$ The elements of the array are leaves of the tree, nu...
2 2 votes
1 1 answer
386
386 views
The two arguments to the function $\textsf{foo(A, n)}$ in the code below are: $\text{(i)}$ an integer array $\textsf{A}$ indexed from $0$, and $\text{(ii)}$ the number $\...
2 2 votes
1 1 answer
281
281 views
The two arguments to the function $\textsf{Mystery(A, n)}$ in the code below are: $\text{(i)}$ an integer array $\textsf{A}$ indexed from $0$, and $\text{(ii)}$ the numbe...