QUESTIONS AND CORRECT DETAILED ANSWERS
WITH RATIONALES (VERIFIED ANSWERS)
|ALREADY GRADED A+ (2026)
Function for deleting nodes, expect for head.
Review_Node delete_by_name(Review_Node head, const char
name_key[]) {
Review_Node *tr=NULL;
Review_Node *pre=NULL;
if (head==NULL) return NULL;
pre=head;
tr=head->next;
// Check if we have to remove the head node
if (strcmp(head->rev.restaurant_name, name_key)==0) {
free(pre);
return tr;
}
while(tr!=NULL) {
if (strcmp(tr->rev.restaurant_name, name_key)==0) {
// Found the node we want to delete
pre->next=tr->next; // Update predecessor pointer
free(tr); // remove node
}
tr=tr->next;
pre=pre->next; }
return head;
// Head did not change
}
,What is a Queue ADT
Collection which items are sequentially ordered
Enqueue
To insert an item into a queue.
Dequeue
To remove an item from the front of a queue.
What is slower to copy? Linked List or Array
Linked List
Strcmp if s1 < s2
Returns < 0
Strcmp if s1 > s2
Returns > 0
What will happen if in a C program you assign a value to an array element
whose subscript exceeds the size of array?
Program may crash if some important data gets overwritten
,What will be the output of the program?
#include<stdio.h>
int main()
{
float a=0.7;
if(a < 0.7)
printf("C ");
else
printf("C++ ");
return 0;
}
If(a < 0.7) here a is a float variable and 0.7 is a double constant. The float
variable a is less than double constant 0.7. Hence the if condition is
satisfied and it prints C
Standard library of printf()
Stdio.h
Int a[5] = {2,3};
When an automatic array is partially initialized, the remaining elements
are initialized to 0.
How many times will this loop run:
for(;scanf("%s", &i); printf("%d ", i));
During the for loop execution scanf() ask input and then printf() prints
that given input. This process will be continued repeatedly because,
scanf() returns the number of input given, the condition is always
true(user gives a input means it reurns ´1´).
Hence this for loop would get executed infinite times.
, Int printf statement identifier
%d
Float printf statement identifier
%f
Double printf statement identifier
%f
Char printf statement identifier
%c
String printf statement identifier
%s
Floating point with scientific notation printf statement identifier
%g
What can you use as a counter for a for loop in C?
Floating point
Non-integer increments
Negative increments
No increments within the body of the for loop
Array