Code Buzz (Language : C)

Reviewed by Editorial Team
The ProProfs editorial team is comprised of experienced subject matter experts. They've collectively created over 10,000 quizzes and lessons, serving over 100 million users. Our team includes in-house content moderators and subject matter experts, as well as a global network of rigorously trained contributors. All adhere to our comprehensive editorial guidelines, ensuring the delivery of high-quality content.
Learn about Our Editorial Process
| By Aniketmondal348
A
Aniketmondal348
Community Contributor
Quizzes Created: 1 | Total Attempts: 81
| Attempts: 81 | Questions: 30
Please wait...
Question 1 / 30
0 %
0/100
Score 0/100
1. Which of the following statements are correct ? 1:            A string is a collection of characters terminated by '\0'. 2:            The format specifier %s is used to print a string. 3:            The length of the string can be obtained by strlen(). 4:            The pointer CANNOT work on string.

Explanation

Statement 1 is correct because a string in C is represented as a collection of characters terminated by a null character '\0'.

Statement 2 is correct because the format specifier %s is used to print a string in C.

Statement 3 is correct because the strlen() function in C can be used to obtain the length of a string.

Statement 4 is incorrect because pointers can work on strings in C.

Submit
Please wait...
About This Quiz
Code Buzz (Language : C) - Quiz

"A good programmer is someone who always looks both ways before crossing a one-way street"
Do you have a wide vision on programming?
Do you have control on several... see morelanguages?
Let's check !Techtix, KGEC in association with Coding Ninjas presents Code Buzz, the competition to test your technical knowledge in Java, C & Python. Code Buzz this year has got total prizes worth Rs. 4,500. Take this challenge and register for Code Buzz this year see less

2. What will be the output of the program ?   #include<stdio.h> #include<string.h>   int main() {     char str1[20] = "Hello", str2[20] = " World";     printf("%s\n", strcpy(str2, strcat(str1, str2)));     return 0; }

Explanation

The program uses the strcpy() and strcat() functions to concatenate the strings str1 and str2. The strcat() function appends str2 to str1, resulting in the string "Hello World". Then, the strcpy() function copies the concatenated string into str2. Therefore, the output of the program is "Hello World".

Submit
3. Declare the following statement? "A pointer to an array of three chars".

Explanation

The correct answer is "char (*ptr)[3]". This is because the declaration "char (*ptr)[3]" declares a pointer named "ptr" that points to an array of three characters. The parentheses are used to indicate that ptr is a pointer, and the brackets [3] indicate that the pointer is pointing to an array of three characters.

Submit
4. Which of the following statement is correct prototype of the malloc() function in c ?

Explanation

The correct prototype of the malloc() function in C is void* malloc(size_t). This is because the malloc() function returns a void pointer (void*) which can be cast to any other pointer type. The size_t parameter is used to specify the number of bytes to allocate for the memory block. This allows for dynamic memory allocation in C, where the size of the memory block can vary at runtime.

Submit
5. What will be the output of the program ?   #include<stdio.h> #include<string.h>   int main() {     printf("%d\n", strlen("123456"));     return 0; }

Explanation

The program uses the strlen() function to determine the length of the string "123456". Since the string has 6 characters, the output of the program will be 6.

Submit
6. What is the purpose of "rb" in fopen() function used below in the code?   FILE *fp; fp = fopen("source.txt", "rb");

Explanation

The purpose of "rb" in the fopen() function is to open the file "source.txt" in binary mode for reading.

Submit
7. What will function gcvt() do?

Explanation

The function gcvt() is used to convert a floating-point number to a string. It takes the floating-point number as input and returns a string representation of that number. This can be useful in situations where we need to display or manipulate the floating-point number as a string, such as in printing or storing the number.

Submit
8. To print out a and b given below, which of the following printf() statement will you use?   #include<stdio.h>   float a=3.14; double b=3.14;

Explanation

The correct answer is printf("%f %lf", a, b) because the format specifier "%f" is used to print a float variable, and the format specifier "%lf" is used to print a double variable. Since "a" is a float and "b" is a double, this printf() statement will correctly print out both variables.

Submit
9. What will be the output of the program?   #include<stdio.h> #include<stdlib.h>   int main() {     int i=0;     i++;     if(i<=5)     {         printf("IndiaBIX");         exit(1);         main();     }     return 0; }

Explanation

The program starts by initializing the variable i to 0. Then, it increments i by 1. The program then checks if i is less than or equal to 5. Since i is 1, the condition is true.

Inside the if statement, the program prints "IndiaBIX" and exits with a status of 1. However, before exiting, the program calls the main() function recursively.

This means that the program will continue to execute from the beginning, incrementing i by 1 each time. Since there is no condition to stop the recursion, it will result in an infinite loop.

Therefore, the program will continuously print "IndiaBIX" and will not terminate.

Submit
10. Which of the following statement is correct?

Explanation

The correct answer is that strcmp(s1, s2) returns 0 if s1==s2. This is because strcmp() is a function in C that compares two strings lexicographically. If the two strings are equal, strcmp() returns 0.

Submit
11. The maximum combined length of the command-line arguments including the spaces between adjacent arguments is

Explanation

The maximum combined length of command-line arguments including spaces can vary from one operating system to another. Different operating systems have different limits on the length of command-line arguments. Therefore, the maximum combined length cannot be determined without considering the specific operating system being used.

Submit
12. What will be the output of the program?   #include<stdio.h> int fun(int); int main() {     float k=3;     fun(k=fun(fun(k)));     printf("%f\n", k);     return 0; } int fun(int i) {     i++;     return i; }

Explanation

The program defines a function `fun` that takes an integer as input and increments it by 1. In the `main` function, a float variable `k` is initialized with the value 3. The `fun` function is called three times on `k` in a nested manner: `fun(k=fun(fun(k)))`. The innermost call to `fun(k)` increments `k` by 1, making it 4. Then, the next call to `fun` increments 4 by 1, making it 5. Finally, the outermost call to `fun` assigns the value 5 to `k`. Therefore, the output of the program will be 5.000000.

Submit
13. Which of the following operations can be performed on the file "NOTES.TXT" using the below code?   FILE *fp; fp = fopen("NOTES.TXT", "r+");

Explanation

The code is using the "r+" mode to open the file "NOTES.TXT". This mode allows both reading and writing operations to be performed on the file. Therefore, the correct answer is "Read and Write".

Submit
14. Which of the following statements are FALSE about the below code?   int main(int ac, char *av[]) { }

Explanation

The statement "In place of ac and av, argc and argv should be used" is false because ac and av are the conventional names for the arguments in the main function in C programming. argc stands for "argument count" and av stands for "argument vector," which are just alternative names for ac and av respectively.

Submit
15. How many times the while loop will get executed if a short int is 2 byte wide?   #include<stdio.h> int main() {     int j=1;     while(j <= 255)     {         printf("%c %d\n", j, j);         j++;     }     return 0; }

Explanation

The while loop will get executed 255 times because the condition in the while loop is "j

Submit
16. What will be the output of the program ?   #include<stdio.h>   int main() {     printf(5+"Good Morning\n");     return 0; }

Explanation

The program will output "Morning". This is because the expression "5+"Good Morning" is equivalent to "Good Morning" + 5, which results in the starting address of the string being incremented by 5. Therefore, the program will print the string starting from the 6th character, which is "Morning".

Submit
17. What do the following declaration signify? char **argv;

Explanation

The declaration "char **argv" signifies that argv is a pointer to a char pointer. This means that argv is a variable that holds the memory address of a char pointer. It can be used to access or manipulate a sequence of char pointers, such as an array of strings.

Submit
18. What will be the output of the program?   #include<stdio.h> int fun(int(*)());   int main() {     fun(main);     printf("Hi\n");     return 0; } int fun(int (*p)()) {     printf("Hello ");     return 0; }

Explanation

The program will output "Hello Hi". The function `fun` is called in the `main` function with `main` as an argument. Inside the `fun` function, "Hello " is printed. Then, in the `main` function, "Hi" is printed. Therefore, the output will be "Hello Hi".

Submit
19. .   Point out the error in the program f(int a, int b) {     int a;     a = 20;     return a; }

Explanation

The error in the program is the redeclaration of the variable "a" inside the function. The variable "a" is already declared as a parameter in the function definition, so redeclaring it inside the function is not allowed and causes a compilation error.

Submit
20. What will be the output of the program ?   #include<stdio.h>   int main() {     char p[] = "%d\n";     p[1] = 'c';     printf(p, 65);     return 0; }

Explanation

The correct answer is "A".

In the given program, the character array "p" is initialized with the format specifier "%d". Then, the character at index 1 of the array "p" is changed to 'c'.

When the printf function is called with the array "p" as the format string and the integer value 65 as the argument, it will print "65" as the output.

Therefore, the output of the program will be "A".

Submit
21. If the size of pointer is 32 bits What will be the output of the program ?   #include<stdio.h>   int main() {     char a[] = "Visual C++";     char *b = "Visual C++";     printf("%d, %d\n", sizeof(a), sizeof(b));     printf("%d, %d", sizeof(*a), sizeof(*b));     return 0; }

Explanation

The size of the array 'a' is 11 because it includes the null character at the end of the string. The size of the pointer 'b' is 4 because it is a 32-bit system and pointers are typically 4 bytes in size. When we use the * operator to dereference the pointers and get the size of the characters they point to, both 'a' and 'b' are of type char, so they have a size of 1 byte. Therefore, the output of the program is "11, 4" and "1, 1".

Submit
22. What will be the output of the program ?   #include<stdio.h> #include<string.h>   int main() {     static char s[] = "Hello!";     printf("%d\n", *(s+strlen(s)));     return 0; }

Explanation

The program will output 0. The variable s is a static character array containing the string "Hello!". The expression *(s+strlen(s)) is equivalent to *(s+6), which is the value at the memory location s+6. Since the string "Hello!" has a length of 6, this expression is accessing the memory location just after the null character at the end of the string. In this case, the value at that memory location happens to be 0. So, when we print *(s+strlen(s)), it will print 0.

Submit
23. What will be the output of the program?   #include<stdio.h>   int main() {     int i;     i = printf("How r u\n");     i = printf("%d\n", i);     printf("%d\n", i);     return 0; }

Explanation

The program first prints "How r u" and returns the number of characters printed, which is 8. This value is then assigned to the variable i. Then, the program prints the value of i, which is 8. Finally, it prints the value of i again, which is still 8. So, the output of the program is "How r u", followed by two lines of "8".

Submit
24. If char=1, int=4, and float=4 bytes size, What will be the output of the program ?   #include<stdio.h>   int main() {     char ch = 'A';     printf("%d, %d, %d", sizeof(ch), sizeof('A'), sizeof(3.14f));     return 0; }

Explanation

The program is using the sizeof() function to determine the size in bytes of different data types. The variable "ch" is of type char and therefore has a size of 1 byte. The character 'A' is also of type char and has a size of 1 byte. The number 3.14f is of type float and has a size of 4 bytes. Therefore, the output of the program will be "1, 4, 4", indicating the size of each data type in bytes.

Submit
25. Point out the error in the program?   #include<stdio.h>   int main() {     FILE *fp;     fp=fopen("trial", "r");     fseek(fp, "20", SEEK_SET);     fclose(fp);     return 0; }

Explanation

The error in the program is that the fseek() function is being passed a string ("20") instead of a long offset value. The fseek() function is used to set the file position indicator for the stream pointed to by the file pointer 'fp'. The third argument of fseek() should be of type long, not a string.

Submit
26. What will the function randomize() do in Turbo C under DOS?

Explanation

The function randomize() in Turbo C under DOS will return a random number generator with a random value based on time. This means that each time the function is called, it will generate a different random value based on the current time. This ensures that the random numbers generated are not predictable and can be used for various purposes such as generating random values in a game or simulation.

Submit
27. What will be the output of the program?   #include<stdio.h>   int main() {     int i;     i = scanf("%d %d", &i, &i);     printf("%d\n", i);     return 0; }

Explanation

The output of the program will be 2. This is because the scanf function is used to read input from the user, and in this case, it is being used to read two integers. The return value of scanf is the number of input items successfully matched and assigned, so in this case, it will be 2. The value of i is not relevant in this case, as it is being overwritten by the scanf function.

Submit
28. What will be the output of the program?   #include<stdio.h> #include<math.h>   int main() {     float i = 2.5;     printf("%f, %d", floor(i), ceil(i));     return 0; }

Explanation

The program uses the floor() and ceil() functions from the math.h library. The floor() function returns the largest integer less than or equal to a given value, while the ceil() function returns the smallest integer greater than or equal to a given value. In this case, the variable i is initialized as 2.5. The floor(i) will return 2, which is the largest integer less than or equal to 2.5. However, the ceil(i) will return 3, which is the smallest integer greater than or equal to 2.5. Therefore, the output of the program will be "2.000000, 0".

Submit
29. Point out the error in the program?   #include<stdio.h>   int main() {     char ch;     int i;     scanf("%c", &i);     scanf("%d", &ch);     printf("%c %d", ch, i);     return 0; }

Explanation

The error in the program is that the format specifier in the first scanf() statement is incorrect. The variable 'i' is an int type, but the format specifier used is '%c' which is for char types. This can cause unexpected behavior or errors when trying to read input into 'i'. Additionally, there is a possibility that the second scanf() statement may not receive any input, which can also cause issues when trying to read the value into 'ch'.

Submit
30. What will be the output of the program in 16-bit platform (Turbo C under DOS) ?   #include<stdio.h>   int main() {     printf("%d, %d, %d", sizeof(3.0f), sizeof('3'), sizeof(3.0));     return 0; }

Explanation

The program uses the sizeof() function to determine the size in bytes of different data types. The first sizeof() function is used on a float value (3.0f), which is a 4-byte data type, so the output is 4. The second sizeof() function is used on a character value ('3'), which is a 1-byte data type, so the output is 1. The third sizeof() function is used on a double value (3.0), which is an 8-byte data type, so the output is 8. Therefore, the output of the program will be 4, 2, 8.

Submit
View My Results

Quiz Review Timeline (Updated): Mar 15, 2023 +

Our quizzes are rigorously reviewed, monitored and continuously updated by our expert board to maintain accuracy, relevance, and timeliness.

  • Current Version
  • Mar 15, 2023
    Quiz Edited by
    ProProfs Editorial Team
  • Mar 06, 2020
    Quiz Created by
    Aniketmondal348
Cancel
  • All
    All (30)
  • Unanswered
    Unanswered ()
  • Answered
    Answered ()
Which of the following statements are correct ? ...
What will be the output of the program ? ...
Declare the following statement? ...
Which of the following statement is correct prototype of the malloc()...
What will be the output of the program ? ...
What is the purpose of "rb" in fopen() function used below...
What will function gcvt() do?
To print out a and b given below, which of the following printf()...
What will be the output of the program? ...
Which of the following statement is correct?
The maximum combined length of the command-line arguments including...
What will be the output of the program? ...
Which of the following operations can be performed on the file...
Which of the following statements are FALSE about the below code? ...
How many times the while loop will get executed if a short int is 2...
What will be the output of the program ? ...
What do the following declaration signify? char **argv;
What will be the output of the program? ...
.   Point out the error in the program ...
What will be the output of the program ? ...
If the size of pointer is 32 bits What will be the output of the...
What will be the output of the program ? ...
What will be the output of the program? ...
If char=1, int=4, and float=4 bytes size, What will be the output of...
Point out the error in the program? ...
What will the function randomize() do in Turbo C under DOS?
What will be the output of the program? ...
What will be the output of the program? ...
Point out the error in the program? ...
What will be the output of the program in 16-bit platform (Turbo C...
Alert!

Advertisement