NEW
Font size
WorksheetsData Structure and Algorithm
Total questions: 15
Worksheet time: 30mins
#include<stdio.h>
int main()
{
int a[] = {1, 2, 3, 4, 5, 6};
int *ptr = (int*)(&a+1);
printf("%d ", *(ptr-1) );
return 0;
}
1
2
6
Runtime Error
Assume
that the size of an integer is 4 bytes, predict the output of following
program.
#include <stdio.h>
int main()
{
int i = 12;
int j = sizeof(i++);
printf("%d , %d", i, j);
return 0;
}
0, 4
12 , 4
13, 4
Compile Time Error
void main()
{
int const * p=5;
printf("%d",++(*p));
}
5
6
Compile Time Error
Runtime Error
#include <stdio.h>
int main()
{
printf("%d", 1 << 2 + 3 << 4);
return 0;
}
52
112
512
0
#define square(x) x*x
void main()
{
int i;
i = 64/square(4);
printf("%d",i);
}
1
4
Compile Time Error
64
What will be the output of the program assuming that the array begins at the location 1002 and size of an integer is 4 bytes?
#include<stdio.h>
int main()
{
int a[3][4] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 };
printf("%u, %u, %u\n", a[0]+1, *(a[0]+1), *(*(a+0)+1));
return 0;
}
448, 4, 4
1006, 2, 2
520, 2, 2
Error
What is the output of the following code
#include<stdio.h>
void main()
{
int x = 5;
if(x==5)
{
if(x==5) break;
printf("Hello");
}
printf("Hi");
}
Hi
HiHello
HelloHi
Compile Time Error
What will be the output of the following ‘C’ code?
void main ( )
{
int x = 128;
printf (“n%d”, 1 + x ++);
}
128
129
130
131
#include<stdio.h>
int main()
{
int n;
for (n = 9; n!=0; n--)
printf("%d ", n--);
return 0;
}
9 8 7 6 5 4 3 2 1
9 7 5 3
9 7 5 3 1
Infinite loop
Predict the output of following program?
# include <stdio.h>
int main()
{
int x = 10;
int y = 20;
x += y += 10;
printf (" %d %d", x, y);
return 0;
}
40 20
40 30
30 30
30 40
What does the following function do for a given Linked List with first node as head?
void fun1(struct node* head)
{
if(head == NULL)
return;
fun1(head->next);
printf("%d ", head->data);
}
Prints all nodes of linked lists
Prints all nodes of linked list in reverse order
Prints alternate nodes of Linked List
Prints alternate nodes in reverse order
Which of the following sorting algorithms can be used to sort a random linked list with minimum time complexity?
Insertion Sort
Quick Sort
Merge Sort
Heap Sort
What is the output of following function for start pointing to first node of following linked list?
1->2->3->4->5->6
void fun(struct node* start)
{
if(start == NULL)
return;
printf("%d ", start->data);
if(start->next != NULL )
fun(start->next->next);
printf("%d ", start->data);
}
1 4 6 6 4 1
1 3 5 5 3 1
1 2 3 5
1 3 5 1 3 5
In the worst case, the number of comparisons needed to search a singly linked list of length N for a given element is:
Log 2 N
N/2
Log 2 N - 1
N
Let P be a singly linked list. Let Q be the pointer to an intermediate node x in the list. What is the worst-case time complexity of the best known algorithm to delete the node x from the list?
O(n)
O(log 2 n)
O(n/2)
O(1)
