C

 48 Minutes
 24 Questions


This test covers a wide range of topics related to the C programming language and its associated technologies. It will assess the student's knowledge of C, including tasks and threads using POSIX Pthreads, the standard library, POSIX I/O, pointers, arrays and strings, data types such as structs and unions, and data structures. The test will also evaluate the student's ability to apply their knowledge of C in practical scenarios.


Example Question:

Multiple-Choice
What will be the output of the following code?
#include<stdio.h>
#include<stdlib.h>
struct node
{
int key_value;
struct node *left;
struct node *right;
};
void insert(int key, struct node **leaf)
{
if( *leaf == 0 )
{
*leaf = (struct node*) malloc( sizeof( struct node ) );
(*leaf)->key_value = key;
(*leaf)->left = 0;
(*leaf)->right = 0;
}
else if(key < (*leaf)->key_value)
{
insert( key, &(*leaf)->left );
}
else if(key > (*leaf)->key_value)
{
insert( key, &(*leaf)->right );
}
}
struct node * find(struct node * root, int val){
if(root->key_value == val)
return root;
if(val < root->key_value){
if(!root->left)
return root;
struct node * p = find(root->left, val);
return abs(p->key_value-val) > abs(root->key_value-val) ? root : p;
}else{
if(!root->right)
return root;
struct node * p = find(root->right, val);
return abs(p->key_value-val) > abs(root->key_value-val) ? root : p;
}
return 0;
}
int main(){
struct node *root = 0;
insert(1,&root);
insert(2,&root);
insert(4,&root);
insert(8,&root);
insert(16,&root);
insert(32,&root);
struct node *res = find(root,11);
struct node *res2 = find(root,3);
printf("
%d",res->key_value);
printf("
%d",res2->key_value);
}