Knowledge check.
- Choose one best answer from given 4 choices for each questions.
- Review before submit as you wont get a chance to review after submit.
- Max Time for quiz is 30 mins and Exam is 90 mins.
- Login is not required for an exam or a quiz.
- By submitting you formally acknowledge and accept terms and conditions mentioned here.
The following program is used to merge the contents of two files. Which of the following statement(s) given in the choices should be corrected to make the program compile, link and run and give the desired output?
#include < stdlib.h>
int main()
{
FILE *fs1, *fs2, *ft;
char ch;
fs1 = fopen("File1.txt", "r");
fs2 = fopen("File2.txt", "r");
if (fs1 == NULL || fs2 == NULL)
{
perror("Error ");
exit(EXIT_FAILURE);
}
ft = fopen("Final.txt", "w");
if (ft == NULL)
{
perror("Error ");
exit(EXIT_FAILURE);
}
while ((ch = fgetc(fs1)) != 0)
fputc(ch, ft);
while ((ch = fgetc(fs2)) != EOF)
fputc(ch, ft);
printf("Two files have been merged successfully");
fclose(fs1);
fclose(fs2);
fclose(ft);
return 0;
}
The following program is used to sort an array of values using Bubble sort technique. Which of the following statement(s) given in the choices should be corrected to make the program compile, link and run and give the desired output?
void bubble_sort(int arry[], int n);
int main()
{
int array[100], n, c;
printf("Enter number of elements\n");
scanf("%d", &n);
printf("Enter %d integers\n", n);
for (c = 0; c < n; c++)
scanf("%d", &array[c]);
bubble_sort(array, n);
printf("Sorted array in ascending order:\n");
for (c = 0; c < n; c++)
printf("%d\n", array[c]);
return 0;
}
void bubble_sort(int arry[], int n)
{
int c, d, temp;
for (c = 0; c < (n - 1); c++)
{
for (d = 0; d < n - c - 1; d++)
{
if (arry[d] > arry[d + 1])
{
temp = arry[d];
arry[d] = arry[d + 1];
arry[d + 1] = arry[d - 1];
}
}
}
}
The following program is used to copy strings without using string function. Which of the following statement(s) given in the choices should be corrected to make the program compile, link and run and give the desired output?
void copy_str(char[], char[]);
int main()
{
char str[100], dest[100];
printf("Input a string\n");
scanf("%s",str);
copy_str(str,dest);
printf("Source string: %s\n", str);
printf("Destination string: %s\n", dest);
return 0;
}
void copy_str(char d[], char s[])
{
int count = 0;
while (s[count] != '\0')
{
d[count] = s[count];
count++;
}
d[count] = '\0';
}
For a given C program, where is the execution started?
Give the output of the following code snippet :
extern void func();
extern int a;
int a=20;
void main()
{
func();
}
void func()
{
printf("%d",a);
}
The following program is used to copy a file. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
#include < stdlib.h>
int main()
{
char ch;
FILE *source, *target;
source = fopen("CopyFile.txt", "r");
if (source == NULL)
{
printf("Press any key to exit...\n");
exit(EXIT_FAILURE);
}
target = fopen("Destination.txt", "w");
if (target == NULL)
{
fclose(source);
printf("Press any key to exit...\n");
exit(EXIT_FAILURE);
}
printf("File copied successfully.\n");
fclose(source);
fclose(target);
return 0;
}
The following program is used to merge the contents of two files. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
#include < stdlib.h>
int main()
{
char ch;
fs1 = fopen("File1.txt", "r");
fs2 = fopen("File2.txt", "r");
if (fs1 == NULL || fs2 == NULL)
{
perror("Error ");
exit(EXIT_FAILURE);
}
ft = fopen("Final.txt", "w");
if (ft == NULL)
{
perror("Error ");
exit(EXIT_FAILURE);
}
while ((ch = fgetc(fs1)) != EOF)
fputc(ch, ft);
while ((ch = fgetc(fs2)) != EOF)
fputc(ch, ft);
printf("Two files have been merged successfully");
fclose(fs1);
fclose(fs2);
fclose(ft);
return 0;
}
The following program is used to swap two values. Which of the following statement(s) given in the choices should be reordered to make the program compile, link and run and give the desired output?
#include < stdio.h>
int main()
{
int value1, value2, temp;
printf("\nEnter the value of value1 : ");
scanf("%d", &value1);
printf("\nEnter the value of value2 : ");
scanf("%d", &value2);
printf("Before Swapping\nvalue1 = %d\nvalue2 = %d\n", value1, value2);
value2 = temp;
temp = value1;
value1 = value2;
printf("After Swapping\nvalue1 = %d\nvalue2 = %d\n", value1, value2);
return 0;
}
What is the return type of the minprintf() function :
The following program is used to merge two arrays into a single array. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
void MergeArrays (int[], int, int[], int, int[]);
int main()
{
int arry1[100], arry2[100], num1, num2, c, result[200];
printf("Input number of elements in first array\n");
scanf("%d", &num1);
printf("Input %d integers\n", num1);
for (c = 0; c < num1; c++)
{
scanf("%d", &arry1[c]);
}
printf("Input number of elements in second array\n");
scanf("%d", &num2);
printf("Input %d integers\n", num2);
for (c = 0; c < num2; c++)
{
scanf("%d", &arry2[c]);
}
MergeArrays(arry1, num1, arry2, num2, result);
printf("Result array:\n");
for (c = 0; c < num1 + num2; c++)
{
printf("%d\n", result[c]);
}
return 0;
}
void MergeArrays (int arry1[], int num1, int arry2[], int num2, int result[])
{
int i, j, k;
j = k = 0;
for (i = 0; i < num1 + num2;)
{
if (j < num1 && k < num2)
{
if (arry1[j] < arry2[k])
{
result[i] = arry1[j];
j++;
}
else
{
result[i] = arry2[k];
k++;
}
i++;
}
else if (j == num1)
{
for (; i < num1 + num2;)
{
result[i] = arry2[k];
k++;
i++;
}
}
else
{
for (; i < num1 + num2;)
{
result[i] = arry1[j];
j++;
i++;
}
}
}
}
Give the output of the following code snippet :
void main()
{
long int x=258L;
int y=10;
long int z;
z=x % y;
printf("%d",z);
}
Give the output of the following code snippet :
int x;
float y;
void main()
{
printf("%d %.2f",x,y);
}
The following program is used to display the student details using structures. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
struct student
{
char name[50];
int studId;
int marks;
};
int main()
{
struct student stud[10];
int i, num;
printf("Enter number of students : \n");
scanf("%d",&num);
printf("Enter information of students:\n");
for (i = 0; i< num; ++i)
{
stud[i].studId = i + 1;
printf("\nStudent ID %d\n", stud[i].studId);
printf("Enter name: ");
scanf("%s", stud[i].name);
printf("Enter marks: ");
scanf("%d", &stud[i].marks);
printf("\n");
}
printf("Student Information :\n\n");
for (i = 0; i< num; ++i)
{
printf("\nStudent ID %d:\n", i + 1);
printf("Name: %s", stud[i].name);
printf("Marks: %d", stud[i].marks);
}
return 0;
}
Give the output of the following code snippet :
void main()
{
printf("%d",printf("Hello World "));
}
The following program is used to generate the fibonacci series. Which of the following statement(s) given in the choices should be reordered to make the program compile, link and run and give the desired output?
#include < stdio.h>
int main()
{
int count, n, num1 = 0, num2 = 1, result = 0;
printf("Enter number of terms: ");
scanf("%d", &n);
printf("Fibonacci Series:\n %d %d ", num1, num2);
count = 2;
while (count< n)
{
result = num1 + num2;
num1 = num2;
num2 = result;
printf("%d ", result);
}
++count;
return 0;
}
Give the output of the following code snippet :
#define max 10
int main()
{
int i;
i=max;
printf("%d",i);
return 0;
}
Input switching is invisible if input comes from another program using pipe mechanism in C.State true or false.
The following program is used to find the factorial of a number. Which of the following statement(s) given in the choices should be corrected to make the program compile, link and run and give the desired output?
#include < stdio.h>
int main()
{
int n, count;
int fact = 1;
printf("Enter a value: ");
scanf("%d", &n);
if (n> 0)
printf("Factorial of negative number does not exist");
else
{
for (count = 1; count < = n; ++count)
{
fact = fact * count;
}
printf("Factorial of %d is %d ",n,fact);
}
return 0;
}
Give the output of the following code snippet :
extern void func();
extern int a;
int a=20;
void main()
{
func();
printf("%d",a);
}
void func()
{
a=200;
printf("%d ",a);
}
The following program is used to concatenate two strings without using string function. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
void str_cat(char[], char[]);
int main()
{
char str1[100], str2[100];
printf("Input a string : \n");
scanf("%s", str1);
printf("Input string to concatenate : \n");
scanf("%s", str2);
str_cat(str1, str2);
printf("String obtained on concatenation : %s \n", str1);
return 0;
}
void str_cat(char str1[], char str2[])
{
int count = 0, d = 0;
while (str1[count] != '\0')
{
count++;
}
while (str2[d] != '\0')
{
str1[count] = str2[d];
d++;
count++;
}
str1[count] = '\0';
}
The following program is used to check if the given number is odd or even. Which of the following statement(s) given in the choices should be corrected to make the program compile, link and run and give the desired output?
#include < stdio.h>
int main()
{
int value;
printf("Enter the value to be checked : ");
scanf("%d", &value);
if ((value * 2) == 0)
printf("%d is even", value);
else
printf("%d is odd ", value);
return 0;
}
Which of the following are conditional directives in C?
The following program is used to merge two arrays into a single array. Which of the following statement(s) given in the choices should be corrected to make the program compile, link and run and give the desired output?
void MergeArrays (int[], int, int[], int, int[]);
int main()
{
int arry1[100], arry2[100], num1, num2, c, result[200];
printf("Input number of elements in first array\n");
scanf("%d", &num1);
printf("Input %d integers\n", num1);
for (c = 0; c < num1; c++)
{
scanf("%d", &arry1[c]);
}
printf("Input number of elements in second array\n");
scanf("%d", &num2);
printf("Input %d integers\n", num2);
for (c = 0; c < num2; c++)
{
scanf("%d", &arry2[c]);
}
MergeArrays(arry1, num1, arry2, num2, result);
printf("Result array:\n");
for (c = 0; c < num1 + num2; c++)
{
printf("%d\n", result[c]);
}
return 0;
}
void MergeArrays (int arry1[], int num1, int arry2[], int num2, int result[])
{
int i, j, k;
j = k = 0;
for (i = 0; i < num1 + num2;)
{
if (j == num1 && k == num2)
{
if (arry1[j] < arry2[k])
{
result[i] = arry1[j];
j++;
}
else
{
result[i] = arry2[k];
k++;
}
i++;
}
else if (j == num1)
{
for (; i < num1 + num2;)
{
result[i] = arry2[k];
k++;
i++;
}
}
else
{
for (; i < num1 + num2;)
{
result[i] = arry1[j];
j++;
i++;
}
}
}
}
The following program is used to merge the contents of two files. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
#include < stdlib.h>
int main()
{
FILE *fs1, *fs2, *ft;
char ch;
fs1 = fopen("File1.txt", "r");
fs2 = fopen("File2.txt", "r");
if (fs1 == NULL || fs2 == NULL)
{
perror("Error ");
exit(EXIT_FAILURE);
}
ft = fopen("Final.txt", "w");
if (ft == NULL)
{
perror("Error ");
exit(EXIT_FAILURE);
}
while ((ch = fgetc(fs1)) != EOF)
fputc(ch, ft);
printf("Two files have been merged successfully");
fclose(fs1);
fclose(fs2);
fclose(ft);
return 0;
}
The following program is used to concatenate two strings without using string function. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
void str_cat(char[], char[]);
int main()
{
char str1[100], str2[100];
printf("Input a string : \n");
scanf("%s", str1);
printf("Input string to concatenate : \n");
scanf("%s", str2);
str_cat(str1, str2);
printf("String obtained on concatenation : %s \n", str1);
return 0;
}
void str_cat(char str1[], char str2[])
{
int count = 0, d = 0;
while (str2[d] != '\0')
{
str1[count] = str2[d];
d++;
count++;
}
str1[count] = '\0';
}
The following program is used to delete a file. Which of the following statement(s) given in the choices should be corrected to make the program compile, link and run and give the desired output?
#include < stdio.h>
int main()
{
int status;
status = delete("Input.txt");
if (status == 0)
printf("File has been deleted successfully\n");
else
{
printf("Unable to delete the file\n");
perror("Error");
}
return 0;
}
Which of the following are not unary operators in C?
The following program is used to find the GCD and LCM of two numbers. Which of the following statement(s) given in the choices should be reordered to make the program compile, link and run and give the desired output?
#include < stdio.h>
int main()
{
int a, b, x, y, temp, gcd, lcm;
printf("Enter two values : \n");
scanf("%d%d", &x, &y);
a = x;
b = y;
while (b != 0)
{
temp = b;
a = temp;
}
b = a % b;
gcd = a;
lcm = (x*y) / gcd;
printf("Greatest common divisor of %d and %d = %d\n", x, y, gcd);
printf("Least common multiple of %d and %d = %d\n", x, y, lcm);
return 0;
}
The following program is used to compare two strings without using string function. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
int str_compare(char[], char[]);
int main()
{
int flag;
char str1[100], str2[100];
printf("Input first string\n");
scanf("%s", str1);
printf("Input second string\n");
scanf("%s", str2);
flag = str_compare(str1, str2);
if (flag == 0)
printf("Entered strings are equal.\n");
else
printf("Entered strings are not equal.\n");
return 0;
}
int str_compare(char a[], char b[])
{
int count = 0;
while (a[count] == b[count])
{
break;
count++;
}
if (a[count] == '\0' && b[count] == '\0')
return 0;
else
return -1;
}
Give the output of the following code snippet :
#define FUNC(a,b) (a*b+20);
void main()
{
int a=3,b=10;
int c=FUNC(a,b);
printf("%d %d %d",a,b,c);
}
What is the meant by ‘a’ in the following operation?
fp = fopen(“New.txt”, “a”);
Give the output of the following code :
void main()
{
char c='a';
printf("Initial value = %c", c);
scanf("%d",&c);
printf("New value=%d",c);
}
Assume that the input given is c='12'. Give the final value of c :
The following program is used to display the student details using structures. Which of the following statement(s) given in the choices should be corrected to make the program compile, link and run and give the desired output?
struct student
{
char name[50];
int studId;
int marks;
};
int main()
{
struct student stud[10];
int i, num;
printf("Enter number of students : \n");
scanf("%d",&num);
printf("Enter information of students:\n");
for (i = 0; i< num; ++i)
{
stud[i].studId = i + 1;
printf("\nStudent ID %d\n", stud[i].studId);
printf("Enter name: ");
scanf("%s", stud[i].name);
printf("Enter marks: ");
scanf("%d", stud[i].marks);
printf("\n");
}
printf("Student Information :\n\n");
for (i = 0; i< num; ++i)
{
printf("\nStudent ID %d:\n", i + 1);
printf("Name: %s", stud[i].name);
printf("Marks: %d", stud[i].marks);
}
return 0;
}
The following program is used to concatenate two strings without using string function. Which of the following statement(s) given in the choices should be corrected to make the program compile, link and run and give the desired output?
void str_cat(char[], char[]);
int main()
{
char str1[100], str2[100];
printf("Input a string : \n");
scanf("%s", str1);
printf("Input string to concatenate : \n");
scanf("%s", str2);
str_cat(str1, str2);
printf("String obtained on concatenation : %s \n", str1);
return 0;
}
void str_cat(char str1[], char str2[])
{
int count = 0, d = 0;
while (str1[count] != '\0')
{
count++;
}
while (str2[d] != '\0')
{
count++;
}
str1[count] = str2[d];
d++;
str1[count] = '\0';
}
The following program is used to merge the contents of two files. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
#include < stdlib.h>
int main()
{
FILE *fs1, *fs2, *ft;
char ch;
if (fs1 == NULL || fs2 == NULL)
{
perror("Error ");
exit(EXIT_FAILURE);
}
ft = fopen("Final.txt", "w");
if (ft == NULL)
{
perror("Error ");
exit(EXIT_FAILURE);
}
while ((ch = fgetc(fs1)) != EOF)
fputc(ch, ft);
while ((ch = fgetc(fs2)) != EOF)
fputc(ch, ft);
printf("Two files have been merged successfully");
fclose(fs1);
fclose(fs2);
fclose(ft);
return 0;
}
Give the output of the following code snippet :
#define fun(x, y) x / y + x
int main()
{
printf("%d ", fun(-3, 3));
return 0;
}
The following program is used to execute a command in the OS. Which of the following statement(s) given in the choices should be corrected to make the program compile, link and run and give the desired output?
#include< stdio.h>
#include< stdlib.h>
int main()
{
int files;
printf("Executing command : 'DIR'\n");
files = system("dirctry");
printf("Returned value is: %d.\n", files);
return 0;
}
The following program is used to find the GCD and LCM of two numbers. Which of the following statement(s) given in the choices should be corrected to make the program compile, link and run and give the desired output?
#include < stdio.h>
int main()
{
int a, b, x, y, temp, gcd, lcm;
printf("Enter two values : \n");
scanf("%d%d", &x, &y);
a = x;
b = y;
while (b != 0)
{
temp = b;
b = a % b;
a = temp;
}
gcd = a % b;
lcm = (x*y) / gcd;
printf("Greatest common divisor of %d and %d = %d\n", x, y, gcd);
printf("Least common multiple of %d and %d = %d\n", x, y, lcm);
return 0;
}
The following program is used to find length of a string without using string function. Which of the following statement(s) given in the choices should be reordered to make the program compile, link and run and give the desired output?
int string_length(char[]);
int main()
{
char str[100];
int length;
length = string_length(str);
printf("Input a string\n");
scanf("%s", str);
printf("Length of string %s = %d\n", str, length);
return 0;
}
int string_length(char s[])
{
int count = 0;
while (s[count] != '\0')
count++;
return count;
}
What is the output of the mathematical function sin(x)?
Which of the following statements is true about the function rand()?
The following program is used to copy a file. Which of the following statement(s) given in the choices should be corrected to make the program compile, link and run and give the desired output?
#include < stdlib.h>
int main()
{
char ch;
FILE *source, *target;
source = fopen("CopyFile.txt", "r");
if (source == NULL)
{
printf("Press any key to exit...\n");
exit(EXIT_FAILURE);
}
target = fopen("Destination.txt", "w");
if (target == NULL)
{
fclose(source);
printf("Press any key to exit...\n");
exit(EXIT_FAILURE);
}
while ((target = fgetc(source)) != EOF)
fputc(ch, target);
printf("File copied successfully.\n");
fclose(source);
fclose(target);
return 0;
}
The following program is used to generate the palindrome of a number. Which of the following statement(s) given in the choices should be corrected to make the program compile, link and run and give the desired output?
#include < stdio.h>
int main()
{
int value,num, reverse = 0;
printf("Enter a number to reverse : ");
scanf("%d", &value);
num = value;
while (num != 0)
{
reverse = reverse * 10;
reverse = reverse + num;
num = num / 10;
}
if (value == reverse)
printf(" %d is a Palindrome",value);
else
printf(" %d is not a Palindrome", value);
return 0;
}
The following program is used to reverse a string. Which of the following statement(s) given in the choices should be corrected to make the program compile, link and run and give the desired output?
#include < stdio.h>
#include < string.h>
int main()
{
char str[100], reverse[100];
int strlength, count, d;
printf("Input a string\n");
scanf("%s",str);
strlength = strlen(str);
for (count = strlength - 1, d = 0; count >= 0; count--, d++)
reverse[d] = str[strlength];
reverse[d] = '\0';
printf("%s\n", reverse);
return 0;
}
The following program is used to merge the contents of two files. Which of the following statement(s) given in the choices should be corrected to make the program compile, link and run and give the desired output?
#include < stdlib.h>
int main()
{
FILE *fs1, *fs2, *ft;
char ch;
fs1 = fopen("File1.txt", "r");
fs2 = fopen("File2.txt", "r");
if (fs1 == NULL || fs2 == NULL)
{
perror("Error ");
exit(EXIT_FAILURE);
}
ft = fopen("Final.txt", "w");
if (ft == 0)
{
perror("Error ");
break;
}
while ((ch = fgetc(fs1)) != EOF)
fputc(ch, ft);
while ((ch = fgetc(fs2)) != EOF)
fputc(ch, ft);
printf("Two files have been merged successfully");
fclose(fs1);
fclose(fs2);
fclose(ft);
return 0;
}
Give the output of the following code snippet :
#define SWAP(a,b)(a=a+b,b=a-b,a=a-b)
void main()
{
int a=3,b=10,c=5;
SWAP(a,b);
printf("%d %d",a,b);
}
Give the output of the following code snippet :
int main()
{
#if VAR
printf("%d",VAR);
#else
printf("Hello World");
#endif
}
Give the output of the following code snippet :
void func(int a)
{
a=200;
printf("%d",a);
}
void main()
{
func(10);
}
Which of the following is an example of an unsigned long hexadecimal constant:
Which of the following is possible with any 2 operators in C?
The following program is used to add 'n' numbers. Which of the following statement(s) given in the choices should be corrected to make the program compile, link and run and give the desired output?
#include< stdio.h>
int main()
{
int num, sum = 0, count, value;
printf("Enter the number of integers to be added : \n");
scanf("%d", &num);
printf("Enter %d integers\n", num);
for (count = 1; count < = num; count++)
{
scanf("%d", &value);
}
sum = sum + value;
printf("Sum of entered integers = %d\n", sum);
return 0;
}
Give the output of the following code snippet :
void fun();
int main()
{
#define test(x, y) x / y + x
fun();
}
void fun()
{
printf("%d\n", test(-3, 3));
}
The following program is used to compare two strings without using string function. Which of the following statement(s) given in the choices should be corrected to make the program compile, link and run and give the desired output?
int str_compare(char[], char[]);
int main()
{
int flag;
char str1[100], str2[100];
printf("Input first string\n");
scanf("%s", str1);
printf("Input second string\n");
scanf("%s", str2);
flag = str_compare();
if (flag == 0)
printf("Entered strings are equal.\n");
else
printf("Entered strings are not equal.\n");
return 0;
}
int str_compare(char a[], char b[])
{
int count = 0;
while (a[count] == b[count])
{
if (a[count] == '\0' || b[count] == '\0')
break;
count++;
}
if (a[count] == '\0' && b[count] == '\0')
return 0;
else
return -1;
}
Which of the following are examples of derived data types?
Give the output of the following code snippet :
void main()
{
int x = 4, y, z;
y = --x;
z = x--;
printf("%d %d %d", x, y, z);
}
The following program is used to merge two arrays into a single array. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
void MergeArrays (int[], int, int[], int, int[]);
int main()
{
int arry1[100], arry2[100], num1, num2, c, result[200];
printf("Input number of elements in first array\n");
scanf("%d", &num1);
printf("Input %d integers\n", num1);
for (c = 0; c < num1; c++)
{
scanf("%d", &arry1[c]);
}
printf("Input number of elements in second array\n");
scanf("%d", &num2);
printf("Input %d integers\n", num2);
for (c = 0; c < num2; c++)
{
scanf("%d", &arry2[c]);
}
MergeArrays(arry1, num1, arry2, num2, result);
printf("Result array:\n");
for (c = 0; c < num1 + num2; c++)
{
printf("%d\n", result[c]);
}
return 0;
}
void MergeArrays (int arry1[], int num1, int arry2[], int num2, int result[])
{
int i, j, k;
j = k = 0;
for (i = 0; i < num1 + num2;)
{
if (j < num1 && k < num2)
{
if (arry1[j] < arry2[k])
{
result[i] = arry1[j];
j++;
}
else
{
k++;
}
i++;
}
else if (j == num1)
{
for (; i < num1 + num2;)
{
result[i] = arry2[k];
k++;
i++;
}
}
else
{
for (; i < num1 + num2;)
{
result[i] = arry1[j];
j++;
i++;
}
}
}
}
In printf function in C, which is the format specifier used to print decimal values?
The following program is used to copy a file. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
#include < stdlib.h>
int main()
{
char ch;
FILE *source, *target;
if (source == NULL)
{
printf("Press any key to exit...\n");
exit(EXIT_FAILURE);
}
target = fopen("Destination.txt", "w");
if (target == NULL)
{
fclose(source);
printf("Press any key to exit...\n");
exit(EXIT_FAILURE);
}
while ((ch = fgetc(source)) != EOF)
fputc(ch, target);
printf("File copied successfully.\n");
fclose(source);
fclose(target);
return 0;
}
Give the output of the following code snippet :
#define CUBE(x)((x)*(x)*(x))
void fun()
{
int x=2,y=1;
int z=CUBE(++x + --y);
printf("%d ",y);
}
void main()
{
int a=3,b=10,c=5;
int d;
fun();
b=CUBE(a+3)/b+c-a;
printf("%d",b);
}
Which standard header contains a set of definitions that define how to step through an argument list in C?
Which of the following are valid #define statements in C?
The following program is used to find the GCD and LCM of two numbers. Which of the following statement(s) given in the choices should be corrected to make the program compile, link and run and give the desired output?
#include < stdio.h>
int main()
{
int a, b, x, y, temp, gcd, lcm;
printf("Enter two values : \n");
scanf("%d%d", &x, &y);
a = x;
b = y;
while (b != 0)
{
temp = b / a;
b = a % b;
a = temp;
}
gcd = a;
lcm = (x*y) / gcd;
printf("Greatest common divisor of %d and %d = %d\n", x, y, gcd);
printf("Least common multiple of %d and %d = %d\n", x, y, lcm);
return 0;
}
The following program is used to concatenate two strings without using string function. Which of the following statement(s) given in the choices should be corrected to make the program compile, link and run and give the desired output?
void str_cat(char[], char[]);
int main()
{
char str1[100], str2[100];
printf("Input a string : \n");
scanf("%s", str1);
printf("Input string to concatenate : \n");
scanf("%s", str2);
str_cat();
printf("String obtained on concatenation : %s \n", str1);
return 0;
}
void str_cat(char str1[], char str2[])
{
int count = 0, d = 0;
while (str1[count] != '\0')
{
count++;
}
while (str2[d] != '\0')
{
str1[count] = str2[d];
d++;
count++;
}
str1[count] = '\0';
}
The following program is used to merge the contents of two files. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
#include < stdlib.h>
int main()
{
FILE *fs1, *fs2, *ft;
char ch;
fs2 = fopen("File2.txt", "r");
if (fs1 == NULL || fs2 == NULL)
{
perror("Error ");
exit(EXIT_FAILURE);
}
ft = fopen("Final.txt", "w");
if (ft == NULL)
{
perror("Error ");
exit(EXIT_FAILURE);
}
while ((ch = fgetc(fs1)) != EOF)
fputc(ch, ft);
while ((ch = fgetc(fs2)) != EOF)
fputc(ch, ft);
printf("Two files have been merged successfully");
fclose(fs1);
fclose(fs2);
fclose(ft);
return 0;
}
What is the default return-type of function putchar()?
Which of the following data types fall under the floating types classification in C?
The following program is used to copy a file. Which of the following statement(s) given in the choices should be reordered to make the program compile, link and run and give the desired output?
#include < stdlib.h>
int main()
{
char ch;
source = fopen("CopyFile.txt", "r");
if (source == NULL)
{
printf("Press any key to exit...\n");
exit(EXIT_FAILURE);
}
target = fopen("Destination.txt", "w");
FILE *source, *target;
if (target == NULL)
{
fclose(source);
printf("Press any key to exit...\n");
exit(EXIT_FAILURE);
}
while ((ch = fgetc(source)) != EOF)
fputc(ch, target);
printf("File copied successfully.\n");
fclose(source);
fclose(target);
return 0;
}
The following program is used to add two complex numbers by passing structure to a function. Which of the following statement(s) given in the choices should be corrected to make the program compile, link and run and give the desired output?
struct complex
{
float real;
float imag;
};
struct int Add(struct complex n1, struct complex n2);
int main()
{
struct complex n1, n2, temp;
printf("For first complex number : \n");
printf("Enter real part :\n");
scanf("%f", &n1.real);
printf("Enter imaginary part :\n");
scanf("%f", &n1.imag);
printf("For second complex number : \n");
printf("Enter real part :\n");
scanf("%f", &n2.real);
printf("Enter imaginary part :\n");
scanf("%f", &n2.imag);
temp = Add(n1, n2);
printf("Sum=%.1f+%.1fi", temp.real, temp.imag);
return 0;
}
struct complex Add(struct complex n1, struct complex n2)
{
struct complex temp;
temp.real = n1.real + n2.real;
temp.imag = n1.imag + n2.imag;
return(temp);
}
Give the output of the following code snippet :
#define A 1 + 2
#define B 3 + 4
int main()
{
int var = A * B;
printf("%d\n", var);
}
The following program is used to display the student details using structures. Which of the following statement(s) given in the choices should be corrected to make the program compile, link and run and give the desired output?
structure student
{
char name[50];
int studId;
int marks;
};
int main()
{
struct student stud[10];
int i, num;
printf("Enter number of students : \n");
scanf("%d",&num);
printf("Enter information of students:\n");
for (i = 0; i< num; ++i)
{
stud[i].studId = i + 1;
printf("\nStudent ID %d\n", stud[i].studId);
printf("Enter name: ");
scanf("%s", stud[i].name);
printf("Enter marks: ");
scanf("%d", &stud[i].marks);
printf("\n");
}
printf("Student Information :\n\n");
for (i = 0; i< num; ++i)
{
printf("\nStudent ID %d:\n", i + 1);
printf("Name: %s", stud[i].name);
printf("Marks: %d", stud[i].marks);
}
return 0;
}
The following program is used to find the maximum value in an array. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
#include< stdio.h>
int main()
{
int array[100], maximum, size, count, location = 1;
printf("\nEnter the number of elements in array : ");
scanf("%d", &size);
printf("Enter %d integers : ", size);
maximum = array[0];
for (count = 1; count < size; count++)
{
if (array[count] > maximum)
{
maximum = array[count];
location = count + 1;
}
}
printf("Maximum element is present at location %d and its value is %d.\n", location, maximum);
return 0;
}
The following program is used to sort an array of structures. Which of the following statement(s) given in the choices should be corrected to make the program compile, link and run and give the desired output?
#include< stdio.h>
struct student
{
char name[50];
int studId;
int marks;
};
int main()
{
struct student stud[10];
int temp;
int i, num;
printf("Enter number of students : \n");
scanf("%d", &num);
printf("Enter information of students:\n");
for (i = 0; i< num; ++i)
{
printf("Enter student ID: ");
scanf("%d", &stud[i].studId);
printf("Enter name: ");
scanf("%s", stud[i].name);
printf("Enter marks: ");
scanf("%d", &stud[i].marks);
printf("\n");
}
for (i = 0; i < num; i++)
for (int j = 0; j < i; j++)
if (stud[i].studId < stud[j].studId)
{
temp = stud[i];
stud[i] = stud[j];
stud[j] = temp;
}
printf("Student Information :\n\n");
for (i = 0; i< num; ++i)
{
printf("\nStudent ID %d:\n",stud[i].studId);
printf("Name: %s", stud[i].name);
printf("Marks: %d", stud[i].marks);
}
return 0;
}
The following program is used to find length of a string without using string function. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
int string_length(char[]);
int main()
{
char str[100];
int length;
printf("Input a string\n");
scanf("%s", str);
length = string_length(str);
printf("Length of string %s = %d\n", str, length);
return 0;
}
int string_length(char s[])
{
int count = 0;
while (s[count] != '\0')
count++;
return count;
}
Consider the following code snippet :
void main()
{
int c=10;
printf("%d",c);
}
Give the value of c before the line 'int c=10' gets executed.
The following program is used to concatenate two strings without using string function. Which of the following statement(s) given in the choices should be reordered to make the program compile, link and run and give the desired output?
void str_cat(char[], char[]);
int main()
{
char str1[100], str2[100];
printf("Input a string : \n");
scanf("%s", str1);
printf("Input string to concatenate : \n");
scanf("%s", str2);
str_cat(str1, str2);
printf("String obtained on concatenation : %s \n", str1);
return 0;
}
void str_cat(char str1[], char str2[])
{
int count = 0, d = 0;
while (str2[d] != '\0')
{
str1[count] = str2[d];
d++;
count++;
}
while (str1[count] != '\0')
{
count++;
}
str1[count] = '\0';
}
The following program is used to merge the contents of two files. Which of the following statement(s) given in the choices should be corrected to make the program compile, link and run and give the desired output?
#include < stdlib.h>
int main()
{
FILE *fs1, *fs2, *ft;
char ch;
fs1 = fopen("File1.txt", "r");
fs2 = fopen("File2.txt", "r");
if (fs1 == NULL || fs2 == NULL)
{
perror("Error ");
exit(EXIT_FAILURE);
}
ft = fopen("Final.txt", "w");
if (ft == fs1)
{
perror("Error ");
exit(EXIT_FAILURE);
}
while ((ch = fgetc(fs1)) != EOF)
fputc(ch, ft);
while ((ch = fgetc(fs2)) != EOF)
fputc(ch, ft);
printf("Two files have been merged successfully");
fclose(fs1);
fclose(fs2);
fclose(ft);
return 0;
}
The following program is used to print the effective username of the current user when invoked. Which of the following statement(s) given in the choices should be added to make the program compile, link and run and give the desired output?
#include < stdio.h>
#include < stdlib.h>
int main()
{
return 0;
}
Give the output of the following code snippet :
#define A 1 + 2
#define B 3 + 4
#define C 2 + 5
int main()
{
int var = A * B - C;
printf("%d\n", var);
}
Which function is used to generate a sequence of pseudo-random integers from a specified range?
The following program is used to merge the contents of two files. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
#include < stdlib.h>
int main()
{
FILE *fs1, *fs2, *ft;
char ch;
if (fs1 == NULL || fs2 == NULL)
{
perror("Error ");
exit(EXIT_FAILURE);
}
ft = fopen("Final.txt", "w");
if (ft == NULL)
{
perror("Error ");
exit(EXIT_FAILURE);
}
while ((ch = fgetc(fs1)) != EOF)
fputc(ch, ft);
while ((ch = fgetc(fs2)) != EOF)
fputc(ch, ft);
printf("Two files have been merged successfully");
fclose(fs1);
fclose(fs2);
fclose(ft);
return 0;
}
Give the output of the following code snippet :
int main()
{
static int a;
printf("%d\n",a);
return 0;
}
The following program is used to find the factorial of a number. Which of the following statement(s) given in the choices should be corrected to make the program compile, link and run and give the desired output?
#include < stdio.h>
int main()
{
int n, count;
int fact = 0;
printf("Enter a value: ");
scanf("%d", &n);
if (n< 0)
printf("Factorial of negative number does not exist");
else
{
for (count = 1; count < = n; ++count)
{
fact = fact * count;
}
printf("Factorial of %d is %d ",n,fact);
}
return 0;
}
Give the output of the following code snippet :
void main()
{
int x = 5.3 % 2;
printf("%d", x);
}
The following program is used to copy a file. Which of the following statement(s) given in the choices should be corrected to make the program compile, link and run and give the desired output?
#include < stdlib.h>
int main()
{
char ch;
FILE *source, *target;
source = fileopen("CopyFile.txt", "r");
if (source == NULL)
{
printf("Press any key to exit...\n");
exit(EXIT_FAILURE);
}
target = fopen("Destination.txt", "w");
if (target == NULL)
{
fclose(source);
printf("Press any key to exit...\n");
exit(EXIT_FAILURE);
}
while ((ch = fgetc(source)) != EOF)
fputc(ch, target);
printf("File copied successfully.\n");
fclose(source);
fclose(target);
return 0;
}
The following program is used to merge two arrays into a single array. Which of the following statement(s) given in the choices should be corrected to make the program compile, link and run and give the desired output?
void MergeArrays (int[], int, int[], int, int[]);
int main()
{
int arry1[100], arry2[100], num1, num2, c, result[200];
printf("Input number of elements in first array\n");
scanf("%d", &num1);
printf("Input %d integers\n", num1);
for (c = 0; c < num1; c++)
{
scanf("%d", &arry1[c]);
}
printf("Input number of elements in second array\n");
scanf("%d", &num2);
printf("Input %d integers\n", num2);
for (c = 0; c < num2; c++)
{
scanf("%d", &arry2[c]);
}
MergeArrays(arry1, num1, arry2, num2, result);
printf("Result array:\n");
for (c = 0; c < num1 + num2; c++)
{
printf("%d\n", result[c]);
}
return 0;
}
void MergeArrays (int arry1[], int num1, int arry2[], int num2, int result[])
{
int i, j, k;
j = k = 0;
for (i = 0; i < num1 + num2;)
{
if (j < num1 && k < num2)
{
if (arry1[j] < arry2[k])
{
result[i] = arry1[j];
j++;
}
else
{
result[i] = arry2[k];
k++;
}
i++;
}
else if (j != num1)
{
for (; i < num1 + num2;)
{
result[i] = arry2[k];
k++;
i++;
}
}
else
{
for (; i < num1 + num2;)
{
result[i] = arry1[j];
j++;
i++;
}
}
}
}
The following program is used to merge two arrays into a single array. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
void MergeArrays (int[], int, int[], int, int[]);
int main()
{
int arry1[100], arry2[100], num1, num2, c, result[200];
printf("Input number of elements in first array\n");
scanf("%d", &num1);
printf("Input %d integers\n", num1);
for (c = 0; c < num1; c++)
{
scanf("%d", &arry1[c]);
}
printf("Input number of elements in second array\n");
scanf("%d", &num2);
printf("Input %d integers\n", num2);
for (c = 0; c < num2; c++)
{
scanf("%d", &arry2[c]);
}
MergeArrays(arry1, num1, arry2, num2, result);
printf("Result array:\n");
for (c = 0; c < num1 + num2; c++)
{
printf("%d\n", result[c]);
}
return 0;
}
void MergeArrays (int arry1[], int num1, int arry2[], int num2, int result[])
{
int i, j, k;
j = k = 0;
for (i = 0; i < num1 + num2;)
{
if (j < num1 && k < num2)
{
if (arry1[j] < arry2[k])
{
result[i] = arry1[j];
j++;
}
else
{
result[i] = arry2[k];
k++;
}
i++;
}
else if (j == num1)
{
for (; i < num1 + num2;)
{
result[i] = arry2[k];
k++;
i++;
}
}
}
}
The following program is used to check if the given number is odd or even. Which of the following statement(s) given in the choices should be corrected to make the program compile, link and run and give the desired output?
#include < stdio.h>
int main()
{
int value;
printf("Enter the value to be checked : ");
scanf("%d", &value);
if ((value % 2) == -1)
printf("%d is even", value);
else
printf("%d is odd ", value);
return 0;
}
Which of the following is the macro substitution directive in C?
The following program is used to copy strings without using string function. Which of the following statement(s) given in the choices should be corrected to make the program compile, link and run and give the desired output?
void copy_str(char[], char[]);
int main()
{
char str[100], dest[100];
printf("Input a string\n");
scanf("%s",str);
copy_str(str);
printf("Source string: %s\n", str);
printf("Destination string: %s\n", dest);
return 0;
}
void copy_str(char d[], char s[])
{
int count = 0;
while (s[count] != '\0')
{
d[count] = s[count];
count++;
}
d[count] = '\0';
}
The following program is used to reverse a string. Which of the following statement(s) given in the choices should be corrected to make the program compile, link and run and give the desired output?
#include < stdio.h>
#include < string.h>
int main()
{
char str[100], reverse[100];
int strlength, count, d;
printf("Input a string\n");
scanf("%s",str);
strlength = strlen(str);
for (count = strlength - 1, d = 0; count >= 0; count--, d++)
reverse[d] = str[count];
reverse[d] = strlen;
printf("%s\n", reverse);
return 0;
}
The following program is used to copy a file. Which of the following statement(s) given in the choices should be corrected to make the program compile, link and run and give the desired output?
#include < lib.h>
int main()
{
char ch;
FILE *source, *target;
source = fopen("CopyFile.txt", "r");
if (source == NULL)
{
printf("Press any key to exit...\n");
exit(EXIT_FAILURE);
}
target = fopen("Destination.txt", "w");
if (target == NULL)
{
fclose(source);
printf("Press any key to exit...\n");
exit(EXIT_FAILURE);
}
while ((ch = fgetc(source)) != EOF)
fputc(ch, target);
printf("File copied successfully.\n");
fclose(source);
fclose(target);
return 0;
}
The following program is used to copy a file. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
#include < stdlib.h>
int main()
{
char ch;
FILE *source, *target;
source = fopen("CopyFile.txt", "r");
if (source == NULL)
{
printf("Press any key to exit...\n");
exit(EXIT_FAILURE);
}
if (target == NULL)
{
fclose(source);
printf("Press any key to exit...\n");
exit(EXIT_FAILURE);
}
while ((ch = fgetc(source)) != EOF)
fputc(ch, target);
printf("File copied successfully.\n");
fclose(source);
fclose(target);
return 0;
}
The following program is used to copy strings without using string function. Which of the following statement(s) given in the choices should be reordered to make the program compile, link and run and give the desired output?
void copy_str(char[], char[]);
int main()
{
char str[100], dest[100];
printf("Input a string\n");
scanf("%s",str);
copy_str(dest, str);
printf("Source string: %s\n", str);
printf("Destination string: %s\n", dest);
return 0;
}
void copy_str(char d[], char s[])
{
int count = 0;
while (s[count] != '\0')
{
d[count] = s[count];
}
count++;
d[count] = '\0';
}
The following program is used to generate the palindrome of a number. Which of the following statement(s) given in the choices should be corrected to make the program compile, link and run and give the desired output?
#include < stdio.h>
int main()
{
int value,num, reverse = 0;
printf("Enter a number to reverse : ");
scanf("%d", &value);
num = value;
if (num == 0)
{
reverse = reverse * 10;
reverse = reverse + num % 10;
num = num / 10;
}
if (value == reverse)
printf(" %d is a Palindrome",value);
else
printf(" %d is not a Palindrome", value);
return 0;
}
The following program is used to copy a file. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
#include < stdlib.h>
int main()
{
char ch;
FILE *source, *target;
source = fopen("CopyFile.txt", "r");
target = fopen("Destination.txt", "w");
if (target == NULL)
{
fclose(source);
printf("Press any key to exit...\n");
exit(EXIT_FAILURE);
}
while ((ch = fgetc(source)) != EOF)
fputc(ch, target);
printf("File copied successfully.\n");
fclose(source);
fclose(target);
return 0;
}
Give the output of the following code snippet :
int main()
{
int x = 2, y = 0;
int z = y && (y != 10);
printf("%d\n", z);
return 0;
}
The following program is used to reverse a string. Which of the following statement(s) given in the choices should be corrected to make the program compile, link and run and give the desired output?
#include < stdio.h>
#include < string.h>
int main()
{
char str[100], reverse[100];
int strlength, count, d;
printf("Input a string\n");
scanf("%s",str);
strlength = strlength(str);
for (count = strlength - 1, d = 0; count >= 0; count--, d++)
reverse[d] = str[count];
reverse[d] = '\0';
printf("%s\n", reverse);
return 0;
}
Give the output of the following code snippet :
#define a 10
#define a 68
int main()
{
printf("%c ",a);
return 0;
}
Give the output of the following code snippet :
void main()
{
1 < 2 ? return 1 : return 2;
}
Which of the following is an example for the format specification %.2f in the scanf() function?
Give the output of the following code snippet :
void main()
{
int x = 98;
char y = x;
printf("%c\n", y);
}
How many arguments does the putc () function take?
Which of the following can be used for random number generation?
Give the output of the following code snippet :
void main()
{
short int x;
long int y;
if(sizeof(x)==sizeof(y))
printf("Hello");
else
printf("World");
}
The following program is used to generate the fibonacci series. Which of the following statement(s) given in the choices should be removed to make the program compile, link and run and give the desired output?
#include < stdio.h>
int main()
{
int count, n, num1 = 0, num2 = 1, result = 0;
printf("Enter number of terms: ");
scanf("%d", &n);
printf("Fibonacci Series:\n %d %d ", num1, num2);
count = 2;
while (count< n)
{
result = num1 + num2;
count = num2;
num1 = num2;
num2 = result;
++count;
printf("%d ", result);
}
return 0;
}
Give the output of the following code snippet :
#define SWAP(a,b)(a=a*b,b=a/b,a=a/b)
void main()
{
int a=3,b=10,c=5;
SWAP(a,b);
printf("%d %d",a,b);
}
The following program is used to add two distances ( inch to feet ) using structures. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
struct Distance
{
int feet;
float inch;
};
struct Distance dist1, dist2, sum;
void main()
{
printf("Enter information for 1st distance\n");
printf("Enter feet: ");
scanf("%d", &dist1.feet);
printf("Enter inch: ");
scanf("%f", &dist1.inch);
printf("\nEnter information for 2nd distance\n");
printf("Enter feet: ");
scanf("%d", &dist2.feet);
printf("Enter inch: ");
scanf("%f", &dist2.inch);
if (sum.inch>12.0)
{
sum.inch = sum.inch - 12.0;
++sum.feet;
}
printf("\nSum of distances=%d\'-%.1f\"", sum.feet, sum.inch);
}
The following program is used to find length of a string without using string function. Which of the following statement(s) given in the choices should be corrected to make the program compile, link and run and give the desired output?
int string_length(char[]);
int main()
{
char str[100];
int length;
printf("Input a string\n");
scanf("%s", str);
length = string_length(str);
printf("Length of string %s = %d\n", str, length);
return 0;
}
int string_length(char s[])
{
int count = 0;
if (s[count] != '\0')
count++;
return count;
}
Which of the following is a valid way to define constants using #define in C?
The following program is used to find length of a string without using string function. Which of the following statement(s) given in the choices should be corrected to make the program compile, link and run and give the desired output?
int string_length(char[]);
int main()
{
char str[100];
int length;
printf("Input a string\n");
scanf("%s", str[100]);
length = string_length(str);
printf("Length of string %s = %d\n", str, length);
return 0;
}
int string_length(char s[])
{
int count = 0;
while (s[count] != '\0')
count++;
return count;
}
The following program is used to check if the given number is odd or even. Which of the following statement(s) given in the choices should be corrected to make the program compile, link and run and give the desired output?
#include < stdio.h>
int main()
{
int value;
printf("Enter the value to be checked : ");
scanf("%d", &value);
if ((value / 2) == 0)
printf("%d is even", value);
else
printf("%d is odd ", value);
return 0;
}
The following program is used to copy a file. Which of the following statement(s) given in the choices should be reordered to make the program compile, link and run and give the desired output?
#include < stdlib.h>
int main()
{
char ch;
FILE *source, *target;
source = fopen("CopyFile.txt", "r");
if (source == NULL)
{
printf("Press any key to exit...\n");
exit(EXIT_FAILURE);
}
while ((ch = fgetc(source)) != EOF)
fputc(ch, target);
target = fopen("Destination.txt", "w");
if (target == NULL)
{
fclose(source);
printf("Press any key to exit...\n");
exit(EXIT_FAILURE);
}
printf("File copied successfully.\n");
fclose(source);
fclose(target);
return 0;
}
Give the output of the following code snippet :
{
int a = 5, b = -7, c = 0, d;
d = ++a && ++b || ++c;
printf("%d %d %d %d ", a,b, c, d);
}
The following program is used to concatenate two strings without using string function. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
void str_cat(char[], char[]);
int main()
{
char str1[100], str2[100];
printf("Input a string : \n");
scanf("%s", str1);
printf("Input string to concatenate : \n");
scanf("%s", str2);
str_cat(str1, str2);
printf("String obtained on concatenation : %s \n", str1);
return 0;
}
void str_cat(char str1[], char str2[])
{
int count = 0, d = 0;
while (str1[count] != '\0')
{
count++;
}
while (str2[d] != '\0')
{
count++;
}
str1[count] = '\0';
}
The following program is used to swap two strings. Which of the following statement(s) given in the choices should be corrected to make the program compile, link and run and give the desired output?
int main()
{
char str1[100], str2[100], temp[50];
printf("Enter the str1 string\n");
scanf("%s", str1);
printf("Enter the str2 string\n");
scanf("%s", str2);
printf("\nBefore Swapping\n");
printf("First string: %s\n", str1);
printf("Second string: %s\n\n", str2);
strcpy(temp, str2);
strcpy(str1, str2);
strcpy(str2, temp);
printf("After Swapping\n");
printf("First string: %s\n", str1);
printf("Second string: %s\n", str2);
return 0;
}
The following program is used to generate the palindrome of a number. Which of the following statement(s) given in the choices should be corrected to make the program compile, link and run and give the desired output?
#include < stdio.h>
int main()
{
int value,num, reverse = 0;
printf("Enter a number to reverse : ");
scanf("%d", &value);
num = value;
while (num != 0)
{
reverse = reverse * 10;
reverse = reverse + num % 10;
num = num + 10;
}
if (value == reverse)
printf(" %d is a Palindrome",value);
else
printf(" %d is not a Palindrome", value);
return 0;
}
Which is true about function tolower in C?
Which of the following are types of C constants ?
How many characters of pushback are guaranteed per file when ungetc() is used.
The following program is used to copy strings without using string function. Which of the following statement(s) given in the choices should be corrected to make the program compile, link and run and give the desired output?
void copy_str(char[], char[]);
int main()
{
char str[100], dest[100];
printf("Input a string\n");
scanf("%s",str);
copy_str(dest, str);
printf("Source string: %s\n", str);
printf("Destination string: %s\n", dest);
return 0;
}
void copy_str()
{
int count = 0;
while (s[count] != '\0')
{
d[count] = s[count];
count++;
}
d[count] = '\0';
}
The following program is used to sort an array of structures. Which of the following statement(s) given in the choices should be corrected to make the program compile, link and run and give the desired output?
#include< stdio.h>
struct student
{
char name[50];
int studId;
int marks;
};
int main()
{
struct student stud,temp;
int i, num;
printf("Enter number of students : \n");
scanf("%d", &num);
printf("Enter information of students:\n");
for (i = 0; i< num; ++i)
{
printf("Enter student ID: ");
scanf("%d", &stud[i].studId);
printf("Enter name: ");
scanf("%s", stud[i].name);
printf("Enter marks: ");
scanf("%d", &stud[i].marks);
printf("\n");
}
for (i = 0; i < num; i++)
for (int j = 0; j < i; j++)
if (stud[i].studId < stud[j].studId)
{
temp = stud[i];
stud[i] = stud[j];
stud[j] = temp;
}
printf("Student Information :\n\n");
for (i = 0; i< num; ++i)
{
printf("\nStudent ID %d:\n",stud[i].studId);
printf("Name: %s", stud[i].name);
printf("Marks: %d", stud[i].marks);
}
return 0;
}
The following program is used to merge two arrays into a single array. Which of the following statement(s) given in the choices should be corrected to make the program compile, link and run and give the desired output?
void MergeArrays (int[], int, int[], int, int[]);
int main()
{
int arry1[100], arry2[100], num1, num2, c, result[200];
printf("Input number of elements in first array\n");
scanf("%d", &num1);
printf("Input %d integers\n", num1);
for (c = 0; c < num1; c++)
{
scanf("%d", &arry1[c]);
}
printf("Input number of elements in second array\n");
scanf("%d", &num2);
printf("Input %d integers\n", num2);
for (c = 0; c < num2; c++)
{
scanf("%d", &arry2[c]);
}
MergeArrays(arry1, num1, arry2, num2, result);
printf("Result array:\n");
for (c = 0; c < num1 + num2; c++)
{
printf("%d\n", result[c]);
}
return 0;
}
void MergeArrays (int arry1[], int num1, int arry2[], int num2, int result[])
{
int i, j, k;
j = k = 0;
for (i = 0; i < num1 + num2;)
{
if (j > num1 && k > num2)
{
if (arry1[j] < arry2[k])
{
result[i] = arry1[j];
j++;
}
else
{
result[i] = arry2[k];
k++;
}
i++;
}
else if (j == num1)
{
for (; i < num1 + num2;)
{
result[i] = arry2[k];
k++;
i++;
}
}
else
{
for (; i < num1 + num2;)
{
result[i] = arry1[j];
j++;
i++;
}
}
}
}
Which of the following is true about the ungetc() function in C?
The following program is used to copy strings without using string function. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
void copy_str(char[], char[]);
int main()
{
char str[100], dest[100];
printf("Input a string\n");
scanf("%s",str);
copy_str(dest, str);
printf("Source string: %s\n", str);
printf("Destination string: %s\n", dest);
return 0;
}
void copy_str(char d[], char s[])
{
int count = 0;
while (s[count] != '\0')
{
d[count] = s[count];
}
d[count] = '\0';
}
Give the output of the following code snippet :
void main()
{
int k = 8;
int m = 7;
int z = k < m ? k++ : m++;
printf("%d", z);
}
The #elif directive cannot be used after the conditional #else directive.
The following program is used to sort an array of structures. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
#include< stdio.h>
struct student
{
char name[50];
int studId;
int marks;
};
int main()
{
struct student stud[10],temp;
int i, num;
printf("Enter number of students : \n");
scanf("%d", &num);
printf("Enter information of students:\n");
for (i = 0; i< num; ++i)
{
printf("Enter student ID: ");
scanf("%d", &stud[i].studId);
printf("Enter name: ");
scanf("%s", stud[i].name);
printf("Enter marks: ");
scanf("%d", &stud[i].marks);
printf("\n");
}
for (i = 0; i < num; i++)
for (int j = 0; j < i; j++)
if (stud[i].studId < stud[j].studId)
{
stud[i] = stud[j];
stud[j] = temp;
}
printf("Student Information :\n\n");
for (i = 0; i< num; ++i)
{
printf("\nStudent ID %d:\n",stud[i].studId);
printf("Name: %s", stud[i].name);
printf("Marks: %d", stud[i].marks);
}
return 0;
}
The following program is used to find the substring in a string without using string function. Which of the following statement(s) given in the choices should corrected to make the program compile, link and run and give the desired output?
int main()
{
char str[100], sub[100];
int position, length, count = 0;
printf("Input a string : \n");
scanf("%s",str);
printf("Enter the position and length of substring\n");
scanf("%d%d", &position, &length);
while (count < length)
{
str[count] = sub[position + count - 1];
count++;
}
sub[count] = '\0';
printf("Required substring is %s\n", sub);
return 0;
}
The following program is used to copy a file. Which of the following statement(s) given in the choices should be corrected to make the program compile, link and run and give the desired output?
#include < stdlib.h>
int main()
{
char ch;
FILE *source, *target;
source = fopen("CopyFile.txt", "r");
if (source == NULL)
{
printf("Press any key to exit...\n");
exit(EXIT_FAILURE);
}
target = fopen(source);
if (target == NULL)
{
fclose(source);
printf("Press any key to exit...\n");
exit(EXIT_FAILURE);
}
while ((ch = fgetc(source)) != EOF)
fputc(ch, target);
printf("File copied successfully.\n");
fclose(source);
fclose(target);
return 0;
}
What are the qualifiers that can be applied to an integer data type in C?
Give the output of the following code :
int main()
{
int x=12, y=7, z;
z = x!=4 || y == 2;
printf("%d\n", z);
return 0;
}
The following program is used to sort an array of structures. Which of the following statement(s) given in the choices should be corrected to make the program compile, link and run and give the desired output?
#include< stdio.h>
struct student
{
char name[50];
int studId;
int marks;
};
int main()
{
struct student[10],temp;
int i, num;
printf("Enter number of students : \n");
scanf("%d", &num);
printf("Enter information of students:\n");
for (i = 0; i< num; ++i)
{
printf("Enter student ID: ");
scanf("%d", &stud[i].studId);
printf("Enter name: ");
scanf("%s", stud[i].name);
printf("Enter marks: ");
scanf("%d", &stud[i].marks);
printf("\n");
}
for (i = 0; i < num; i++)
for (int j = 0; j < i; j++)
if (stud[i].studId < stud[j].studId)
{
temp = stud[i];
stud[i] = stud[j];
stud[j] = temp;
}
printf("Student Information :\n\n");
for (i = 0; i< num; ++i)
{
printf("\nStudent ID %d:\n",stud[i].studId);
printf("Name: %s", stud[i].name);
printf("Marks: %d", stud[i].marks);
}
return 0;
}
The following program is used to generate the palindrome of a number. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
#include < stdio.h>
int main()
{
int value,num, reverse = 0;
printf("Enter a number to reverse : ");
scanf("%d", &value);
num = value;
while (num != 0)
{
reverse = reverse * 10;
reverse = reverse + num % 10;
num = num / 10;
}
if (value == reverse)
printf(" %d is a Palindrome",value);
else
printf(" %d is not a Palindrome", value);
return 0;
}
The following program is used to sort an array of values using Bubble sort technique. Which of the following statement(s) given in the choices should be corrected to make the program compile, link and run and give the desired output?
void bubble_sort(int arry[], int n);
int main()
{
int array[100], n, c;
printf("Enter number of elements\n");
scanf("%d", &n);
printf("Enter %d integers\n", n);
for (c = 0; c < n; c++)
scanf("%d", &array[c]);
bubble_sort(array, n);
printf("Sorted array in ascending order:\n");
for (c = 0; c < n; c++)
printf("%d\n", array[c]);
return 0;
}
void bubble_sort(int arry[], int n)
{
int c, d, temp;
for (c = 0; c < (n - 1); c++)
{
for (d = 0; d > n ; d++)
{
if (arry[d] > arry[d + 1])
{
temp = arry[d];
arry[d] = arry[d + 1];
arry[d + 1] = temp;
}
}
}
}
The following program is used to check if the given number is a prime number or not. Which of the following statement(s) given in the choices should be corrected to make the program compile, link and run and give the desired output?
#include< stdio.h>
int main()
{
int value, i, flag = 0;
printf("Enter a positive value: ");
scanf("%d", &value);
for (i = 2; i < = value % 2; ++i)
{
if (value % i == 0)
{
flag = 1;
break;
}
}
if (flag == 0)
printf("%d is a prime number", value);
else
printf("%d is not a prime number", value);
return 0;
}
The following program is used to delete an element from an array. Which of the following statement(s) given in the choices should be removed to make the program compile, link and run and give the desired output?
#include< stdio.h>
int main()
{
int array[100], position, count, n;
printf("Enter number of elements in array : \n");
scanf("%d", &n);
printf("Enter %d elements : \n", n);
for (count = 0; count < n; count++)
scanf("%d", &array[count]);
printf("Enter the location where you wish to delete element : \n");
scanf("%d", &position);
if (position >= n + 1)
printf("Deletion not possible.\n");
else
{
for (count = position - 1; count < n - 1; count++)
{
array[count] = array[count + 1];
array[count + 1] = array[count -1];
}
printf("Resultant array : ");
for (count = 0; count < n - 1; count++)
printf("%d\n", array[count]);
}
return 0;
}
The following program is used to add two complex numbers by passing structure to a function. Which of the following statement(s) given in the choices should be corrected to make the program compile, link and run and give the desired output?
structure complex
{
float real;
float imag;
};
struct complex Add(struct complex n1, struct complex n2);
int main()
{
struct complex n1, n2, temp;
printf("For first complex number : \n");
printf("Enter real part :\n");
scanf("%f", &n1.real);
printf("Enter imaginary part :\n");
scanf("%f", &n1.imag);
printf("For second complex number : \n");
printf("Enter real part :\n");
scanf("%f", &n2.real);
printf("Enter imaginary part :\n");
scanf("%f", &n2.imag);
temp = Add(n1, n2);
printf("Sum=%.1f+%.1fi", temp.real, temp.imag);
return 0;
}
struct complex Add(struct complex n1, struct complex n2)
{
struct complex temp;
temp.real = n1.real + n2.real;
temp.imag = n1.imag + n2.imag;
return(temp);
}
Give the output of the following code snippet :
void func(int i)
{
void j;
j=i;
printf("%d",j);
}
void main()
{
int x=10;
func(x);
printf("%d",x);
}
Which of the following are types of C constants ?
The following program is used to compare two strings without using string function. Which of the following statement(s) given in the choices should be corrected to make the program compile, link and run and give the desired output?
int str_compare(char[], char[]);
int main()
{
int flag;
char str1[100], str2[100];
printf("Input first string\n");
scanf("%s", str1);
printf("Input second string\n");
scanf("%s", str2);
flag = str_compare(str1, str2);
if (flag == 0)
printf("Entered strings are equal.\n");
else
printf("Entered strings are not equal.\n");
return 0;
}
int str_compare(char a[], char b[])
{
int count = 0;
while (a[count] == b[count])
{
while (a[count] == '\0' || b[count] == '\0')
continue;
count++;
}
if (a[count] == '\0' && b[count] == '\0')
return 0;
else
return -1;
}
The following program is used to delete an element from an array. Which of the following statement(s) given in the choices should be reordered to make the program compile, link and run and give the desired output?
#include< stdio.h>
int main()
{
int array[100], position, count, n;
printf("Enter %d elements : \n", n);
for (count = 0; count < n; count++)
scanf("%d", &array[count]);
printf("Enter number of elements in array : \n");
scanf("%d", &n);
printf("Enter the location where you wish to delete element : \n");
scanf("%d", &position);
if (position >= n + 1)
printf("Deletion not possible.\n");
else
{
for (count = position - 1; count < n - 1; count++)
array[count] = array[count + 1];
printf("Resultant array : ");
for (count = 0; count < n - 1; count++)
printf("%d\n", array[count]);
}
return 0;
}
The value of EOF (End of file) :
The following program is used to copy strings without using string function. Which of the following statement(s) given in the choices should be corrected to make the program compile, link and run and give the desired output?
void copy_str(char[], char[]);
int main()
{
char str[100], dest[100];
printf("Input a string\n");
scanf("%s",str);
copy_str(dest, str);
printf("Source string: %s\n", str);
printf("Destination string: %s\n", dest);
return 0;
}
void copy_str(char d[], char s[])
{
int count = 0;
while (s[count] != '\0')
{
d[count] = s[count];
count--;
}
d[count] = '\0';
}
The following program is used to sort an array of values using Bubble sort technique. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
void bubble_sort(int arry[], int n);
int main()
{
int array[100], n, c;
printf("Enter number of elements\n");
scanf("%d", &n);
printf("Enter %d integers\n", n);
for (c = 0; c < n; c++)
scanf("%d", &array[c]);
bubble_sort(array, n);
printf("Sorted array in ascending order:\n");
for (c = 0; c < n; c++)
printf("%d\n", array[c]);
return 0;
}
void bubble_sort(int arry[], int n)
{
int c, d, temp;
for (c = 0; c < (n - 1); c++)
{
for (d = 0; d < n - c - 1; d++)
{
if (arry[d] > arry[d + 1])
{
arry[d + 1] = temp;
}
}
}
}
Give the output of the following code snippet:
#define SQUARE(x) x*x
int main()
{
float t=2,a;
a =SQUARE(t);
printf("Result = %f", a);
return 0;
}
Give the output of the following code snippet :
#if(10)
int main()
{
printf("Hello World");
return 0;
}
#else
int main()
{
printf("Hello World :Round two");
}
#endif
The following program is used to sort an array of values using Bubble sort technique. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
void bubble_sort(int arry[], int n);
int main()
{
int array[100], n, c;
printf("Enter number of elements\n");
scanf("%d", &n);
printf("Enter %d integers\n", n);
for (c = 0; c < n; c++)
scanf("%d", &array[c]);
bubble_sort(array, n);
printf("Sorted array in ascending order:\n");
for (c = 0; c < n; c++)
printf("%d\n", array[c]);
return 0;
}
void bubble_sort(int arry[], int n)
{
int c, d, temp;
for (c = 0; c < (n - 1); c++)
{
for (d = 0; d < n - c - 1; d++)
{
if (arry[d] > arry[d + 1])
{
temp = arry[d];
arry[d + 1] = temp;
}
}
}
}
The following program is used to delete an element from an array. Which of the following statement(s) given in the choices should be corrected to make the program compile, link and run and give the desired output?
#include< stdio.h>
int main()
{
int array[100], position, count, n;
printf("Enter number of elements in array : \n");
scanf("%d", &n);
printf("Enter %d elements : \n", n);
for (count = 0; count < n; count++)
scanf("%d", &array[count]);
printf("Enter the location where you wish to delete element : \n");
scanf("%d", &position);
if (position >= n + 1)
printf("Deletion not possible.\n");
else
{
for (count = 0; count < position; count++)
array[count] = array[count + 1];
printf("Resultant array : ");
for (count = 0; count < n - 1; count++)
printf("%d\n", array[count]);
}
return 0;
}
The following program is used to compare two strings without using string function. Which of the following statement(s) given in the choices should be reordered to make the program compile, link and run and give the desired output?
int str_compare(char[], char[]);
int main()
{
int flag;
char str1[100], str2[100];
printf("Input first string\n");
scanf("%s", str1);
printf("Input second string\n");
scanf("%s", str2);
flag = str_compare(str1, str2);
if (flag == 0)
printf("Entered strings are equal.\n");
else
printf("Entered strings are not equal.\n");
return 0;
}
int str_compare(char a[], char b[])
{
int count = 0;
if (a[count] == '\0' || b[count] == '\0')
break;
while (a[count] == b[count])
{
count++;
}
if (a[count] == '\0' && b[count] == '\0')
return 0;
else
return -1;
}
Give the use of the -(minus) sign in the prinft() format control string :
In printf function in C, which is the format specifier used to print strings?
The following program is used to swap two strings. Which of the following statement(s) given in the choices should be removed to make the program compile, link and run and give the desired output?
int main()
{
char str1[100], str2[100], temp[50];
printf("Enter the str1 string\n");
scanf("%s", str1);
printf("Enter the str2 string\n");
scanf("%s", str2);
printf("\nBefore Swapping\n");
printf("First string: %s\n", str1);
printf("Second string: %s\n\n", str2);
strcpy(temp, str1);
strcpy(str1, str2);
strcpy(str2, str1);
strcpy(str2, temp);
printf("After Swapping\n");
printf("First string: %s\n", str1);
printf("Second string: %s\n", str2);
return 0;
}
The following program is used to add two distances ( inch to feet ) using structures. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
struct Distance dist1, dist2, sum;
void main()
{
printf("Enter information for 1st distance\n");
printf("Enter feet: ");
scanf("%d", &dist1.feet);
printf("Enter inch: ");
scanf("%f", &dist1.inch);
printf("\nEnter information for 2nd distance\n");
printf("Enter feet: ");
scanf("%d", &dist2.feet);
printf("Enter inch: ");
scanf("%f", &dist2.inch);
sum.feet = dist1.feet + dist2.feet;
sum.inch = dist1.inch + dist2.inch;
if (sum.inch>12.0)
{
sum.inch = sum.inch - 12.0;
++sum.feet;
}
printf("\nSum of distances=%d\'-%.1f\"", sum.feet, sum.inch);
}
The following program is used to merge the contents of two files. Which of the following statement(s) given in the choices should be reordered to make the program compile, link and run and give the desired output?
#include < stdlib.h>
int main()
{
FILE *fs1, *fs2, *ft;
char ch;
fs1 = fopen("File1.txt", "r");
fs2 = fopen("File2.txt", "r");
if (fs1 == NULL || fs2 == NULL)
{
perror("Error ");
exit(EXIT_FAILURE);
}
if (ft == NULL)
{
perror("Error ");
exit(EXIT_FAILURE);
}
while ((ch = fgetc(fs1)) != EOF)
fputc(ch, ft);
while ((ch = fgetc(fs2)) != EOF)
fputc(ch, ft);
ft = fopen("Final.txt", "w");
printf("Two files have been merged successfully");
fclose(fs1);
fclose(fs2);
fclose(ft);
return 0;
}
While including a header file, if the file name is specified between quotes, then where is the file searched?
The following program is used to find length of a string without using string function. Which of the following statement(s) given in the choices should be corrected to make the program compile, link and run and give the desired output?
int string_length(char[]);
int main()
{
char str[100];
int length;
printf("Input a string\n");
scanf("%s", str);
length = string_length(str);
printf("Length of string %s = %d\n", str, length);
return 0;
}
void string_length(char s[])
{
int count = 0;
while (s[count] != '\0')
count++;
return count;
}
The following program is used to copy a file. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
#include < stdlib.h>
int main()
{
char ch;
FILE *source, *target;
if (source == NULL)
{
printf("Press any key to exit...\n");
exit(EXIT_FAILURE);
}
target = fopen("Destination.txt", "w");
if (target == NULL)
{
fclose(source);
printf("Press any key to exit...\n");
exit(EXIT_FAILURE);
}
while ((ch = fgetc(source)) != EOF)
fputc(ch, target);
printf("File copied successfully.\n");
fclose(source);
fclose(target);
return 0;
}
The following program is used to check if the given number is a prime number or not. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
#include< stdio.h>
int main()
{
int value, i, flag = 0;
printf("Enter a positive value: ");
scanf("%d", &value);
for (i = 2; i < = value / 2; ++i)
{
if (value % i == 0)
{
break;
}
}
if (flag == 0)
printf("%d is a prime number", value);
else
printf("%d is not a prime number", value);
return 0;
}
Which of the following is a ternary operator?
The following program is used to add two complex numbers by passing structure to a function. Which of the following statement(s) given in the choices should be corrected to make the program compile, link and run and give the desired output?
struct complex
{
float real;
float imag;
};
struct complex Add(complex n1, complex n2);
int main()
{
struct complex n1, n2, temp;
printf("For first complex number : \n");
printf("Enter real part :\n");
scanf("%f", &n1.real);
printf("Enter imaginary part :\n");
scanf("%f", &n1.imag);
printf("For second complex number : \n");
printf("Enter real part :\n");
scanf("%f", &n2.real);
printf("Enter imaginary part :\n");
scanf("%f", &n2.imag);
temp = Add(n1, n2);
printf("Sum=%.1f+%.1fi", temp.real, temp.imag);
return 0;
}
struct complex Add(struct complex n1, struct complex n2)
{
struct complex temp;
temp.real = n1.real + n2.real;
temp.imag = n1.imag + n2.imag;
return(temp);
}
The following program is used to sort an array of structures. Which of the following statement(s) given in the choices should be corrected to make the program compile, link and run and give the desired output?
#include< stdio.h>
struct student
{
char name[50];
int studId;
int marks;
};
int main()
{
struct student stud[10],temp;
int i, num;
printf("Enter number of students : \n");
scanf("%d", &num);
printf("Enter information of students:\n");
for (i = 0; i< num; ++i)
{
printf("Enter student ID: ");
scanf("%d", &stud[i].studId);
printf("Enter name: ");
scanf("%s", stud[i].name);
printf("Enter marks: ");
scanf("%d", &stud[i].marks);
printf("\n");
}
for (i = 0; i < num; i++)
for (int j = 0; j < i; j++)
if (stud[i].studId == stud[j].studId)
{
temp = stud[i];
stud[i] = stud[j];
stud[j] = temp;
}
printf("Student Information :\n\n");
for (i = 0; i< num; ++i)
{
printf("\nStudent ID %d:\n",stud[i].studId);
printf("Name: %s", stud[i].name);
printf("Marks: %d", stud[i].marks);
}
return 0;
}
The following program is used to find the maximum value in an array. Which of the following statement(s) given in the choices should be reordered to make the program compile, link and run and give the desired output?
#include< stdio.h>
int main()
{
int array[100], maximum, size, count, location = 1;
printf("\nEnter the number of elements in array : ");
scanf("%d", &size);
printf("Enter %d integers : ", size);
for (count = 0; count < size; count++)
scanf("\n%d", &array[count]);
maximum = array[0];
for (count = 1; count < size; count++)
{
if (array[count] > maximum)
{
location = count + 1;
}
maximum = array[count];
}
printf("Maximum element is present at location %d and its value is %d.\n", location, maximum);
return 0;
}
The following program is used to find the maximum value in an array. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
#include< stdio.h>
int main()
{
int array[100], maximum, size, count, location = 1;
printf("\nEnter the number of elements in array : ");
scanf("%d", &size);
printf("Enter %d integers : ", size);
for (count = 0; count < size; count++)
scanf("\n%d", &array[count]);
maximum = array[0];
for (count = 1; count < size; count++)
{
if (array[count] > maximum)
{
maximum = array[count];
location = count + 1;
}
}
printf("Maximum element is present at location %d and its value is %d.\n", location, maximum);
return 0;
}
Give the output of the following code snippet :
void main()
{
int b = 5 & 4 & 6;
printf("%d", b);
}
The following program is used to delete an element from an array. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
#include< stdio.h>
int main()
{
int array[100], position, count, n;
printf("Enter number of elements in array : \n");
scanf("%d", &n);
printf("Enter %d elements : \n", n);
for (count = 0; count < n; count++)
scanf("%d", &array[count]);
printf("Enter the location where you wish to delete element : \n");
scanf("%d", &position);
if (position >= n + 1)
printf("Deletion not possible.\n");
else
{
printf("Resultant array : ");
for (count = 0; count < n - 1; count++)
printf("%d\n", array[count]);
}
return 0;
}
What are the restrictions places on the names of variables and constants in C?
The following program is used to display the student details using structures. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
{
char name[50];
int studId;
int marks;
};
int main()
{
struct student stud[10];
int i, num;
printf("Enter number of students : \n");
scanf("%d",&num);
printf("Enter information of students:\n");
for (i = 0; i< num; ++i)
{
stud[i].studId = i + 1;
printf("\nStudent ID %d\n", stud[i].studId);
printf("Enter name: ");
scanf("%s", stud[i].name);
printf("Enter marks: ");
scanf("%d", &stud[i].marks);
printf("\n");
}
printf("Student Information :\n\n");
for (i = 0; i< num; ++i)
{
printf("\nStudent ID %d:\n", i + 1);
printf("Name: %s", stud[i].name);
printf("Marks: %d", stud[i].marks);
}
return 0;
}
Give the output of the following code snippet :
#define join(p,q) p##q
int main()
{
int join(a,b)=45;
printf("%d",ab);
return 0;
}
Give the output of the following code snippet :
#define FUNC(x) while(i!=0) \
{\
i--;\
x--;\
printf("%d ",x);\
}
int main()
{
int z=10,i=2;
FUNC(z);
}
Give the output of the following code snippet :
int main()
{
#ifdef Hello
printf("Hello\t");
#else
printf("World\t");
#endif
}
The following program is used to generate the fibonacci series. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
#include < stdio.h>
int main()
{
int count, n, num1 = 0, num2 = 1, result = 0;
printf("Enter number of terms: ");
scanf("%d", &n);
printf("Fibonacci Series:\n %d %d ", num1, num2);
count = 2;
while (count< n)
{
result = num1 + num2;
num1 = num2;
++count;
printf("%d ", result);
}
return 0;
}
In printf function in C, which is the format specifier used to print hexadecimal values?
The following program is used to add two complex numbers by passing structure to a function. Which of the following statement(s) given in the choices should be corrected to make the program compile, link and run and give the desired output?
struct complex
{
float real;
float imag;
};
complex Add(struct complex n1, struct complex n2);
int main()
{
struct complex n1, n2, temp;
printf("For first complex number : \n");
printf("Enter real part :\n");
scanf("%f", &n1.real);
printf("Enter imaginary part :\n");
scanf("%f", &n1.imag);
printf("For second complex number : \n");
printf("Enter real part :\n");
scanf("%f", &n2.real);
printf("Enter imaginary part :\n");
scanf("%f", &n2.imag);
temp = Add(n1, n2);
printf("Sum=%.1f+%.1fi", temp.real, temp.imag);
return 0;
}
struct complex Add(struct complex n1, struct complex n2)
{
struct complex temp;
temp.real = n1.real + n2.real;
temp.imag = n1.imag + n2.imag;
return(temp);
}
The following program is used to delete an element from an array. Which of the following statement(s) given in the choices should be corrected to make the program compile, link and run and give the desired output?
#include< stdio.h>
int main()
{
int array[100], position, count, n;
printf("Enter number of elements in array : \n");
scanf("%d", &n);
printf("Enter %d elements : \n", n);
for (count = 0; count < n; count++)
scanf("%d", &array[count]);
printf("Enter the location where you wish to delete element : \n");
scanf("%d", &position);
if (position >= n + 1)
printf("Deletion not possible.\n");
else
{
for (count = position - 1; count > 0; count--)
array[count] = array[count + 1];
printf("Resultant array : ");
for (count = 0; count < n - 1; count++)
printf("%d\n", array[count]);
}
return 0;
}
Give the output of the following code :
void main()
{
int x = 0, y = 2, z = 3;
int a = x & y | z;
printf("%d", a);
}
The following program is used to add 'n' numbers. Which of the following statement(s) given in the choices should be corrected to make the program compile, link and run and give the desired output?
#include< stdio.h>
int main()
{
int num, sum = 0, count, value;
printf("Enter the number of integers to be added : \n");
scanf("%d", &num);
printf("Enter %d integers\n", num);
for (count = sum; count < = 0 ; count--)
{
scanf("%d", &value);
sum = sum + value;
}
printf("Sum of entered integers = %d\n", sum);
return 0;
}
Give the output of the following code snippet :
void main()
{
int k = sqrt(-4);
printf("%d\n", k);
}
Which of the following are examples of mathematical functions in C?
Which of the following statements is true about the function srand()?
The following program is used to merge two arrays into a single array. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
void MergeArrays (int[], int, int[], int, int[]);
int main()
{
int arry1[100], arry2[100], num1, num2, c, result[200];
printf("Input number of elements in first array\n");
scanf("%d", &num1);
printf("Input %d integers\n", num1);
for (c = 0; c < num1; c++)
{
scanf("%d", &arry1[c]);
}
printf("Input number of elements in second array\n");
scanf("%d", &num2);
printf("Input %d integers\n", num2);
for (c = 0; c < num2; c++)
{
scanf("%d", &arry2[c]);
}
MergeArrays(arry1, num1, arry2, num2, result);
printf("Result array:\n");
for (c = 0; c < num1 + num2; c++)
{
printf("%d\n", result[c]);
}
return 0;
}
void MergeArrays (int arry1[], int num1, int arry2[], int num2, int result[])
{
int i, j, k;
j = k = 0;
for (i = 0; i < num1 + num2;)
{
if (j < num1 && k < num2)
{
if (arry1[j] < arry2[k])
{
result[i] = arry1[j];
j++;
}
else
{
result[i] = arry2[k];
k++;
}
i++;
}
else if (j == num1)
{
for (; i < num1 + num2;)
{
i++;
}
}
else
{
for (; i < num1 + num2;)
{
result[i] = arry1[j];
j++;
i++;
}
}
}
}
The following program is used to find the factorial of a number. Which of the following statement(s) given in the choices should be corrected to make the program compile, link and run and give the desired output?
#include < stdio.h>
int main()
{
int n, count;
int fact = 1;
printf("Enter a value: ");
scanf("%d", &n);
if (n< 0)
printf("Factorial of negative number does not exist");
else
{
for (count = 1; count < = fact; ++count)
{
fact = fact * count;
}
printf("Factorial of %d is %d ",n,fact);
}
return 0;
}
Which of the following data types fall under the floating types classification in C?
The following program is used to copy strings without using string function. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
void copy_str(char[], char[]);
int main()
{
char str[100], dest[100];
printf("Input a string\n");
scanf("%s",str);
copy_str(dest, str);
printf("Source string: %s\n", str);
printf("Destination string: %s\n", dest);
return 0;
}
void copy_str(char d[], char s[])
{
int count = 0;
while (s[count] != '\0')
{
d[count] = s[count];
count++;
}
d[count] = '\0';
}
The following program is used to sort an array of structures. Which of the following statement(s) given in the choices should be corrected to make the program compile, link and run and give the desired output?
#include< stdio.h>
struct student
{
char name[50];
int studId;
int marks;
};
int main()
{
struct student stud[10],temp;
int i, num;
printf("Enter number of students : \n");
scanf("%d", &num);
printf("Enter information of students:\n");
for (i = 0; i< num; ++i)
{
printf("Enter student ID: ");
scanf("%d", &stud[i].studId);
printf("Enter name: ");
scanf("%s", stud[i].name);
printf("Enter marks: ");
scanf("%d", &stud[i].marks);
printf("\n");
}
for (i = 0; i < num; i++)
for (int j = 0; j < i; j++)
if (stud[i].studId < stud[j].studId)
{
temp = stud[i];
temp = stud[j];
stud[j] = temp;
}
printf("Student Information :\n\n");
for (i = 0; i< num; ++i)
{
printf("\nStudent ID %d:\n",stud[i].studId);
printf("Name: %s", stud[i].name);
printf("Marks: %d", stud[i].marks);
}
return 0;
}
The following program is used to sort an array of structures. Which of the following statement(s) given in the choices should be corrected to make the program compile, link and run and give the desired output?
#include< stdio.h>
struct student
{
char name[50];
int studId;
int marks;
};
int main()
{
struct student stud[10],temp;
int i, num;
printf("Enter number of students : \n");
scanf("%d", &num);
printf("Enter information of students:\n");
for (i = 0; i< num; ++i)
{
printf("Enter student ID: ");
scanf("%d", &stud[i].studId);
printf("Enter name: ");
scanf("%s", stud[i].name);
printf("Enter marks: ");
scanf("%d", &stud[i].marks);
printf("\n");
}
for (i = 0; i < num; i++)
for (int j = 0; j < i; j++)
if (struct[i].studId < struct[j].studId)
{
temp = stud[i];
stud[i] = stud[j];
stud[j] = temp;
}
printf("Student Information :\n\n");
for (i = 0; i< num; ++i)
{
printf("\nStudent ID %d:\n",stud[i].studId);
printf("Name: %s", stud[i].name);
printf("Marks: %d", stud[i].marks);
}
return 0;
}
Give the output of the following code snippet :
void fun()
{
printf("%d\n", test(-3, 3));
}
int main()
{
#define test(x, y) x / y + x
fun();
}
The following program is used to generate the fibonacci series. Which of the following statement(s) given in the choices should be reordered to make the program compile, link and run and give the desired output?
#include < stdio.h>
int main()
{
int count, n, num1 = 0, num2 = 1, result = 0;
printf("Enter number of terms: ");
scanf("%d", &n);
printf("Fibonacci Series:\n %d %d ", num1, num2);
count = 2;
while (count< n)
{
result = num1 + num2;
++count;
printf("%d ", result);
}
num1 = num2;
num2 = result;
return 0;
}
The following program is used to generate the fibonacci series. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
#include < stdio.h>
int main()
{
int count, n, num1 = 0, num2 = 1, result = 0;
printf("Enter number of terms: ");
scanf("%d", &n);
printf("Fibonacci Series:\n %d %d ", num1, num2);
count = 2;
{
result = num1 + num2;
num1 = num2;
num2 = result;
++count;
printf("%d ", result);
}
return 0;
}
Give the output of the following code snippet :
#define CUBE(x) (x*x*x)
#define M 10
#define N M+1
int main()
{
int volume =CUBE(3+2);
printf("%d %d ",volume,N);
return 0;
}
The following program is used to check if the given number is odd or even. Which of the following statement(s) given in the choices should be corrected to make the program compile, link and run and give the desired output?
#include < stdio.h>
int main()
{
int value;
printf("Enter the value to be checked : ");
scanf("%d", &value);
if ((value % 2) == 0)
printf("%d is even", value);
else if ((value / 2) == -1)
value++;
else
printf("%d is odd ", value);
return 0;
}
The following program is used to find length of a string without using string function. Which of the following statement(s) given in the choices should be reordered to make the program compile, link and run and give the desired output?
int string_length(char[]);
int main()
{
char str[100];
int length;
printf("Input a string\n");
scanf("%s", str);
length = string_length(str);
printf("Length of string %s = %d\n", str, length);
return 0;
}
int string_length(char s[])
{
int count = 0;
count++;
while (s[count] != '\0')
return count;
}
The following program is used to add two distances ( inch to feet ) using structures. Which of the following statement(s) given in the choices should be corrected to make the program compile, link and run and give the desired output?
struct Distance
{
int feet;
float inch;
};
struct Distance dist1, dist2, sum;
void main()
{
printf("Enter information for 1st distance\n");
printf("Enter feet: ");
scanf("%d", &dist1.feet);
printf("Enter inch: ");
scanf("%f", &dist1.inch);
printf("\nEnter information for 2nd distance\n");
printf("Enter feet: ");
scanf("%d", &dist2.feet);
printf("Enter inch: ");
scanf("%f", &dist2.inch);
sum = dist1.feet + dist2.feet;
sum.inch = dist1.inch + dist2.inch;
if (sum.inch>12.0)
{
sum.inch = sum.inch - 12.0;
++sum.feet;
}
printf("\nSum of distances=%d\'-%.1f\"", sum.feet, sum.inch);
}
Name the escape sequence to print a tab space in printf function in C :
The following program is used to generate the fibonacci series. Which of the following statement(s) given in the choices should be corrected to make the program compile, link and run and give the desired output?
#include < stdio.h>
int main()
{
int count, n, num1 = 0, num2 = 1, result = 0;
printf("Enter number of terms: ");
scanf("%d", &n);
printf("Fibonacci Series:\n %d %d ", num1, num2);
count = 2;
if (count< n)
{
result = num1 + num2;
num1 = num2;
num2 = result;
++count;
printf("%d ", result);
}
return 0;
}
Relational operators have greater precedence than arithmetic operators. True or false?
Give the output of the following code snippet :
void func();
void main()
{
int a=100;
#define VAR 200
func();
printf("%d ",VAR+a);
}
#define VAR 100
void func()
{
printf("%d ",VAR);
}
Shifting a value x two positions to the left i.e x << 2 is equivalent to :
The following program is used to generate the palindrome of a number. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
#include < stdio.h>
int main()
{
int value,num, reverse = 0;
printf("Enter a number to reverse : ");
scanf("%d", &value);
num = value;
{
reverse = reverse * 10;
reverse = reverse + num % 10;
num = num / 10;
}
if (value == reverse)
printf(" %d is a Palindrome",value);
else
printf(" %d is not a Palindrome", value);
return 0;
}
The following program is used to add two complex numbers by passing structure to a function. Which of the following statement(s) given in the choices should be reordered to make the program compile, link and run and give the desired output?
struct complex
{
float real;
float imag;
};
struct complex Add(struct complex n1, struct complex n2);
int main()
{
struct complex n1, n2, temp;
printf("For first complex number : \n");
printf("Enter real part :\n");
scanf("%f", &n1.real);
printf("Enter imaginary part :\n");
scanf("%f", &n1.imag);
printf("For second complex number : \n");
printf("Enter real part :\n");
scanf("%f", &n2.real);
printf("Enter imaginary part :\n");
scanf("%f", &n2.imag);
temp = Add(n1, n2);
printf("Sum=%.1f+%.1fi", temp.real, temp.imag);
return 0;
}
struct complex Add(struct complex n1, struct complex n2)
{
return(temp);
struct complex temp;
temp.real = n1.real + n2.real;
temp.imag = n1.imag + n2.imag;
}
The following program is used to compare two strings without using string function. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
int str_compare(char[], char[]);
int main()
{
int flag;
char str1[100], str2[100];
printf("Input first string\n");
scanf("%s", str1);
printf("Input second string\n");
scanf("%s", str2);
flag = str_compare(str1, str2);
if (flag == 0)
printf("Entered strings are equal.\n");
else
printf("Entered strings are not equal.\n");
return 0;
}
int str_compare(char a[], char b[])
{
int count = 0;
while (a[count] == b[count])
{
if (a[count] == '\0' || b[count] == '\0')
break;
count++;
}
return -1;
}
The following program is used to concatenate two strings without using string function. Which of the following statement(s) given in the choices should be corrected to make the program compile, link and run and give the desired output?
void str_cat(char[], char[]);
int main()
{
char str1[100], str2[100];
printf("Input a string : \n");
scanf("%s", str1);
printf("Input string to concatenate : \n");
scanf("%s", str2);
str_cat(str1, str2);
printf("String obtained on concatenation : %s \n", str1);
return 0;
}
void str_cat(char str1[], char str2[])
{
int count = 0, d = 0;
if (str1[count] != '\0')
{
count++;
}
while (str2[d] != '\0')
{
str1[count] = str2[d];
d++;
count++;
}
str1[count] = '\0';
}
The function ungetc() may be used with which of the following functions?
The following program is used to delete a file. Which of the following statement(s) given in the choices should be corrected to make the program compile, link and run and give the desired output?
#include < stdio.h>
int main()
{
int status;
status = remove("Input.txt");
if (status != 0)
printf("File has been deleted successfully\n");
else
{
printf("Unable to delete the file\n");
perror("Error");
}
return 0;
}
Which of the following are examples of derived data types?
The following program is used to delete an element from an array. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
#include< stdio.h>
int main()
{
int array[100], position, count, n;
printf("Enter number of elements in array : \n");
scanf("%d", &n);
printf("Enter %d elements : \n", n);
for (count = 0; count < n; count++)
scanf("%d", &array[count]);
printf("Enter the location where you wish to delete element : \n");
scanf("%d", &position);
if (position >= n + 1)
printf("Deletion not possible.\n");
else
{
for (count = position - 1; count < n - 1; count++)
printf("Resultant array : ");
for (count = 0; count < n - 1; count++)
printf("%d\n", array[count]);
}
return 0;
}
The following program is used to copy a file. Which of the following statement(s) given in the choices should be corrected to make the program compile, link and run and give the desired output?
#include < stdlib.h>
int main()
{
char ch;
FILE *source, *target;
source = fopen("CopyFile.txt", "r");
if (source == NULL)
{
printf("Press any key to exit...\n");
exit(EXIT_FAILURE);
}
target = fopen("Destination.txt", "w");
if (target == NULL)
{
fclose(source);
printf("Press any key to exit...\n");
exit(EXIT_FAILURE);
}
while ((ch = fopen(source)) != EOF)
fputc(ch, target);
printf("File copied successfully.\n");
fclose(source);
fclose(target);
return 0;
}
The preprocessor provides the ability for which of the following options?
Give the output of the following code snippet :
void main()
{
int n;
scanf("%d",&n);
printf("%d", n);
}
Assume input to n is 'c'
The following program is used to add two complex numbers by passing structure to a function. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
struct complex
{
float real;
float imag;
};
struct complex Add(struct complex n1, struct complex n2);
int main()
{
struct complex n1, n2, temp;
printf("For first complex number : \n");
printf("Enter real part :\n");
scanf("%f", &n1.real);
printf("Enter imaginary part :\n");
scanf("%f", &n1.imag);
printf("For second complex number : \n");
printf("Enter real part :\n");
scanf("%f", &n2.real);
printf("Enter imaginary part :\n");
scanf("%f", &n2.imag);
temp = Add(n1, n2);
printf("Sum=%.1f+%.1fi", temp.real, temp.imag);
return 0;
}
struct complex Add(struct complex n1, struct complex n2)
{
struct complex temp;
temp.imag = n1.imag + n2.imag;
return(temp);
}
Give the output of the following code snippet :
int main()
{
int i = 10, j = 20, k = 30;
printf("%d %d ", i, j, k);
}
The following program is used to print the effective username of the current user when invoked. Which of the following statement(s) given in the choices should be added to make the program compile, link and run and give the desired output?
#include < stdio.h>
#include < stdlib.h>
int main()
{
return 0;
}
The following program is used to copy strings without using string function. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
void copy_str(char[], char[]);
int main()
{
char str[100], dest[100];
printf("Input a string\n");
scanf("%s",str);
copy_str(dest, str);
printf("Source string: %s\n", str);
printf("Destination string: %s\n", dest);
return 0;
}
void copy_str(char d[], char s[])
{
int count = 0;
while (s[count] != '\0')
{
d[count] = s[count];
count++;
}
}
The “else if” in conditional inclusion is written as?
Give the output of the following code snippet :
void main()
{
int b = 5 + 7 * 4 - 9 * (3-2);
printf("%d", b);
}
The following program is used to print the effective username of the current user when invoked. Which of the following statement(s) given in the choices should be added to make the program compile, link and run and give the desired output?
#include < stdio.h>
#include < stdlib.h>
int main()
{
return 0;
}
The following program is used to display the student details using structures. Which of the following statement(s) given in the choices should be corrected to make the program compile, link and run and give the desired output?
struct student
{
char name[50];
int studId;
int marks;
};
int main()
{
struct student stud[10];
int i, num;
printf("Enter number of students : \n");
scanf("%d",&num);
printf("Enter information of students:\n");
for (i = 0; i< num; ++i)
{
stud[i].studId = i + 1;
printf("\nStudent ID %d\n", stud[i].studId);
printf("Enter name: ");
scanf("%s", stud.name);
printf("Enter marks: ");
scanf("%d", &stud[i].marks);
printf("\n");
}
printf("Student Information :\n\n");
for (i = 0; i< num; ++i)
{
printf("\nStudent ID %d:\n", i + 1);
printf("Name: %s", stud[i].name);
printf("Marks: %d", stud[i].marks);
}
return 0;
}
The following program is used to find the substring in a string without using string function. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
int main()
{
char str[100], sub[100];
int position, length, count = 0;
printf("Enter the position and length of substring\n");
scanf("%d%d", &position, &length);
while (count < length)
{
sub[count] = str[position + count - 1];
count++;
}
sub[count] = '\0';
printf("Required substring is %s\n", sub);
return 0;
}
The following program is used to add two complex numbers by passing structure to a function. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
struct complex
{
float real;
float imag;
};
struct complex Add(struct complex n1, struct complex n2);
int main()
{
struct complex n1, n2, temp;
printf("For first complex number : \n");
printf("Enter real part :\n");
scanf("%f", &n1.real);
printf("Enter imaginary part :\n");
scanf("%f", &n1.imag);
printf("For second complex number : \n");
printf("Enter real part :\n");
scanf("%f", &n2.real);
printf("Enter imaginary part :\n");
scanf("%f", &n2.imag);
temp = Add(n1, n2);
printf("Sum=%.1f+%.1fi", temp.real, temp.imag);
return 0;
}
struct complex Add(struct complex n1, struct complex n2)
{
struct complex temp;
temp.real = n1.real + n2.real;
temp.imag = n1.imag + n2.imag;
}
Give the output of the following code snippet :
void main()
{
int x=3.105,y=6.6678;
double z=ceil((double)x)/floor((double)y);
printf("%.2f",z);
}
Give the output of the following code :
void main()
{
int b = 6;
int c = 7;
int a = ++b + c--;
printf("%d", a);
}
The following program is used to print the IP address of the system. Which of the following statement(s) given in the choices should be added to make the program compile, link and run and give the desired output?
#include < stdio.h>
#include < stdlib.h>
int main()
{
return 0;
}
In printf function in C, which is the format specifier used to print characters?
The following program is used to merge two arrays into a single array. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
void MergeArrays (int[], int, int[], int, int[]);
int main()
{
int arry1[100], arry2[100], num1, num2, c, result[200];
printf("Input number of elements in first array\n");
scanf("%d", &num1);
printf("Input %d integers\n", num1);
for (c = 0; c < num1; c++)
{
scanf("%d", &arry1[c]);
}
printf("Input number of elements in second array\n");
scanf("%d", &num2);
printf("Input %d integers\n", num2);
for (c = 0; c < num2; c++)
{
scanf("%d", &arry2[c]);
}
MergeArrays(arry1, num1, arry2, num2, result);
printf("Result array:\n");
for (c = 0; c < num1 + num2; c++)
{
printf("%d\n", result[c]);
}
return 0;
}
void MergeArrays (int arry1[], int num1, int arry2[], int num2, int result[])
{
int i, j, k;
j = k = 0;
for (i = 0; i < num1 + num2;)
{
if (j < num1 && k < num2)
{
if (arry1[j] < arry2[k])
{
result[i] = arry1[j];
j++;
}
else
{
result[i] = arry2[k];
k++;
}
i++;
}
else
{
for (; i < num1 + num2;)
{
result[i] = arry1[j];
j++;
i++;
}
}
}
}
The %(modulo) operator cannot be applied for which data type?
The following program is used to sort an array of structures. Which of the following statement(s) given in the choices should be corrected to make the program compile, link and run and give the desired output?
#include< stdio.h>
struct student
{
char name[50];
int studId;
int marks;
};
int main()
{
struct student stud[10],temp;
int i, num;
printf("Enter number of students : \n");
scanf("%d", &num);
printf("Enter information of students:\n");
for (i = 0; i< num; ++i)
{
printf("Enter student ID: ");
scanf("%d", &stud[i].studId);
printf("Enter name: ");
scanf("%s", stud[i].name);
printf("Enter marks: ");
scanf("%d", &stud[i].marks);
printf("\n");
}
for (i = 0; i < num; i++)
for (int j = 0; j < i; j++)
if (student[i].studId < student[j].studId)
{
temp = stud[i];
stud[i] = stud[j];
stud[j] = temp;
}
printf("Student Information :\n\n");
for (i = 0; i< num; ++i)
{
printf("\nStudent ID %d:\n",stud[i].studId);
printf("Name: %s", stud[i].name);
printf("Marks: %d", stud[i].marks);
}
return 0;
}
The following program is used to sort an array of values using Bubble sort technique. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
void bubble_sort(int arry[], int n);
int main()
{
int array[100], n, c;
printf("Enter number of elements\n");
scanf("%d", &n);
printf("Enter %d integers\n", n);
for (c = 0; c < n; c++)
scanf("%d", &array[c]);
bubble_sort(array, n);
printf("Sorted array in ascending order:\n");
for (c = 0; c < n; c++)
printf("%d\n", array[c]);
return 0;
}
void bubble_sort(int arry[], int n)
{
int c, d, temp;
for (d = 0; d < n - c - 1; d++)
{
if (arry[d] > arry[d + 1])
{
temp = arry[d];
arry[d] = arry[d + 1];
arry[d + 1] = temp;
}
}
}
Give the output of the following code snippet :
void func(int a)
{
int a=200;
printf("%d",a);
}
void main()
{
func(10);
}
The following program is used to copy strings without using string function. Which of the following statement(s) given in the choices should be removed to make the program compile, link and run and give the desired output?
void copy_str(char[], char[]);
int main()
{
char str[100], dest[100];
printf("Input a string\n");
scanf("%s",str);
copy_str(dest, str);
printf("Source string: %s\n", str);
printf("Destination string: %s\n", dest);
return 0;
}
void copy_str(char d[], char s[])
{
int count = 0;
while (s[count] != '\0')
{
d[count] = s[count];
d[count] = d[count-1];
count++;
}
d[count] = '\0';
}
Which of the following data types fall under the integral types classification in C?
Give the output of the following code snippet :
void main()
{
int x = 5 % 2 * 4 / 2;
printf("%d", x);
}
Give the output of the following code snippet :
#if 0
int main()
{
printf("Hello World");
return 0;
}
#endif
The following program is used to merge two arrays into a single array. Which of the following statement(s) given in the choices should be corrected to make the program compile, link and run and give the desired output?
void MergeArrays (int[], int, int[], int, int[]);
int main()
{
int arry1[100], arry2[100], num1, num2, c, result[200];
printf("Input number of elements in first array\n");
scanf("%d", &num1);
printf("Input %d integers\n", num1);
for (c = 0; c < num1; c++)
{
scanf("%d", &arry1[c]);
}
printf("Input number of elements in second array\n");
scanf("%d", &num2);
printf("Input %d integers\n", num2);
for (c = 0; c < num2; c++)
{
scanf("%d", &arry2[c]);
}
MergeArrays(arry1, num1, arry2, num2, result);
printf("Result array:\n");
for (c = 0; c < num1 + num2; c++)
{
printf("%d\n", result[c]);
}
return 0;
}
void MergeArrays (int arry1[], int num1, int arry2[], int num2, int result[])
{
int i, j, k;
j = k = 0;
for (i = 0; i < num1 / num2; i++)
{
if (j < num1 && k < num2)
{
if (arry1[j] < arry2[k])
{
result[i] = arry1[j];
j++;
}
else
{
result[i] = arry2[k];
k++;
}
i++;
}
else if (j == num1)
{
for (; i < num1 + num2;)
{
result[i] = arry2[k];
k++;
i++;
}
}
else
{
for (; i < num1 + num2;)
{
result[i] = arry1[j];
j++;
i++;
}
}
}
}
Name the library function used in C to get the input from the user through the console :
The macro va_start initializes the argument pointer to point to ?
What are the restrictions places on the names of variables and constants in C?
Give the output of the following code snippet :
void main()
{
int b = 5 - 4 + 2 * 5;
printf("%d", b);
}
A long definition for the replacement text in macros can be continued for several lines using which operator?
The following program is used to merge two arrays into a single array. Which of the following statement(s) given in the choices should be corrected to make the program compile, link and run and give the desired output?
void MergeArrays ();
int main()
{
int arry1[100], arry2[100], num1, num2, c, result[200];
printf("Input number of elements in first array\n");
scanf("%d", &num1);
printf("Input %d integers\n", num1);
for (c = 0; c < num1; c++)
{
scanf("%d", &arry1[c]);
}
printf("Input number of elements in second array\n");
scanf("%d", &num2);
printf("Input %d integers\n", num2);
for (c = 0; c < num2; c++)
{
scanf("%d", &arry2[c]);
}
MergeArrays(arry1, num1, arry2, num2, result);
printf("Result array:\n");
for (c = 0; c < num1 + num2; c++)
{
printf("%d\n", result[c]);
}
return 0;
}
void MergeArrays (int arry1[], int num1, int arry2[], int num2, int result[])
{
int i, j, k;
j = k = 0;
for (i = 0; i < num1 + num2;)
{
if (j < num1 && k < num2)
{
if (arry1[j] < arry2[k])
{
result[i] = arry1[j];
j++;
}
else
{
result[i] = arry2[k];
k++;
}
i++;
}
else if (j == num1)
{
for (; i < num1 + num2;)
{
result[i] = arry2[k];
k++;
i++;
}
}
else
{
for (; i < num1 + num2;)
{
result[i] = arry1[j];
j++;
i++;
}
}
}
}
Give the output of the following code snippet :
#define MAX(x,y) (x)>(y)?(x):(y)
int main()
{
int i=10,j=9,k=0;
k=MAX(i++,++j);
printf("%d %d %d",i,j,k);
return 0;
}
Binary operators * and / have what priority?
Each call to the macro va_arg,
The following program is used to find the GCD and LCM of two numbers. Which of the following statement(s) given in the choices should be reordered to make the program compile, link and run and give the desired output?
#include < stdio.h>
int main()
{
int a, b, x, y, temp, gcd, lcm;
printf("Enter two values : \n");
scanf("%d%d", &x, &y);
a = x;
b = y;
temp = b;
while (b != 0)
{
b = a % b;
a = temp;
}
gcd = a;
lcm = (x*y) / gcd;
printf("Greatest common divisor of %d and %d = %d\n", x, y, gcd);
printf("Least common multiple of %d and %d = %d\n", x, y, lcm);
return 0;
}
The following program is used to generate the palindrome of a number. Which of the following statement(s) given in the choices should be reordered to make the program compile, link and run and give the desired output?
#include < stdio.h>
int main()
{
int value,num, reverse = 0;
printf("Enter a number to reverse : ");
scanf("%d", &value);
num = value;
reverse = reverse * 10;
while (num != 0)
{
reverse = reverse + num % 10;
num = num / 10;
}
if (value == reverse)
printf(" %d is a Palindrome",value);
else
printf(" %d is not a Palindrome", value);
return 0;
}
The following program is used to swap two values. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
#include < stdio.h>
int main()
{
int value1, value2, temp;
printf("\nEnter the value of value1 : ");
scanf("%d", &value1);
printf("\nEnter the value of value2 : ");
scanf("%d", &value2);
printf("Before Swapping\nvalue1 = %d\nvalue2 = %d\n", value1, value2);
value2 = temp;
printf("After Swapping\nvalue1 = %d\nvalue2 = %d\n", value1, value2);
return 0;
}
Give the output of the following code snippet :
#define func(x, y) x + y - x
int main()
{
int i = 3, j = 3;
printf("%d\n",func(i*j, 2));
return 0;
}
In printf function in C, which is the format specifier used to print floating point values?
The following program is used to check if the given number is a prime number or not. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
#include< stdio.h>
int main()
{
int value, i, flag = 0;
printf("Enter a positive value: ");
scanf("%d", &value);
for (i = 2; i < = value / 2; ++i)
{
if (value % i == 0)
{
flag = 1;
}
}
if (flag == 0)
printf("%d is a prime number", value);
else
printf("%d is not a prime number", value);
return 0;
}
Give the output of the following code :
#define Message "Hello World"
int main()
{
printf("%d\n",Message);
return 0;
}
The following program is used to display the student details using structures. Which of the following statement(s) given in the choices should be corrected to make the program compile, link and run and give the desired output?
struct student
{
char name[50];
int studId;
int marks;
};
int main()
{
struct student stud[10];
int i, num;
printf("Enter number of students : \n");
scanf("%d",&num);
printf("Enter information of students:\n");
for (i = 0; i< num; ++i)
{
stud[i].studId = i + 1;
printf("\nStudent ID %d\n", stud[i].studId);
printf("Enter name: ");
scanf("%s", stud -> name);
printf("Enter marks: ");
scanf("%d", &stud[i].marks);
printf("\n");
}
printf("Student Information :\n\n");
for (i = 0; i< num; ++i)
{
printf("\nStudent ID %d:\n", i + 1);
printf("Name: %s", stud[i].name);
printf("Marks: %d", stud[i].marks);
}
return 0;
}
The following program is used to merge the contents of two files. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
#include < stdlib.h>
int main()
{
FILE *fs1, *fs2, *ft;
char ch;
fs1 = fopen("File1.txt", "r");
fs2 = fopen("File2.txt", "r");
if (fs1 == NULL || fs2 == NULL)
{
perror("Error ");
}
ft = fopen("Final.txt", "w");
if (ft == NULL)
{
perror("Error ");
exit(EXIT_FAILURE);
}
while ((ch = fgetc(fs1)) != EOF)
fputc(ch, ft);
while ((ch = fgetc(fs2)) != EOF)
fputc(ch, ft);
printf("Two files have been merged successfully");
fclose(fs1);
fclose(fs2);
fclose(ft);
return 0;
}
The following program is used to swap two values. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
#include < stdio.h>
int main()
{
int value1, value2, temp;
printf("\nEnter the value of value1 : ");
scanf("%d", &value1);
printf("\nEnter the value of value2 : ");
scanf("%d", &value2);
printf("Before Swapping\nvalue1 = %d\nvalue2 = %d\n", value1, value2);
temp = value1;
value1 = value2;
printf("After Swapping\nvalue1 = %d\nvalue2 = %d\n", value1, value2);
return 0;
}
Give the output of the following code snippet :
#define max 10+2
int main()
{
int i;
i=max*max;
printf("%d",i);
return 0;
}
The following program is used to generate the palindrome of a number. Which of the following statement(s) given in the choices should be reordered to make the program compile, link and run and give the desired output?
#include < stdio.h>
int main()
{
int value,num, reverse = 0;
printf("Enter a number to reverse : ");
scanf("%d", &value);
num = value;
while (num != 0)
{
reverse = reverse * 10;
num = num / 10;
}
reverse = reverse + num % 10;
if (value == reverse)
printf(" %d is a Palindrome",value);
else
printf(" %d is not a Palindrome", value);
return 0;
}
The following program is used to merge the contents of two files. Which of the following statement(s) given in the choices should be reordered to make the program compile, link and run and give the desired output?
#include < stdlib.h>
int main()
{
FILE *fs1, *fs2, *ft;
char ch;
if (fs1 == NULL || fs2 == NULL)
{
perror("Error ");
exit(EXIT_FAILURE);
}
fs1 = fopen("File1.txt", "r");
fs2 = fopen("File2.txt", "r");
ft = fopen("Final.txt", "w");
if (ft == NULL)
{
perror("Error ");
exit(EXIT_FAILURE);
}
while ((ch = fgetc(fs1)) != EOF)
fputc(ch, ft);
while ((ch = fgetc(fs2)) != EOF)
fputc(ch, ft);
printf("Two files have been merged successfully");
fclose(fs1);
fclose(fs2);
fclose(ft);
return 0;
}
Give the output of the following code snippet :
#define Hello
int main()
{
#ifdef Hello
printf("Hello\t");
#undef Hello
#endif
#ifdef Hello
printf("World\t");
#endif
}