Blind Coding C Programming Practice Quiz!

Approved & Edited by ProProfs Editorial Team
The editorial team at ProProfs Quizzes consists of a select group of subject experts, trivia writers, and quiz masters who have authored over 10,000 quizzes taken by more than 100 million users. This team includes our in-house seasoned quiz moderators and subject matter experts. Our editorial experts, spread across the world, are rigorously trained using our comprehensive guidelines to ensure that you receive the highest quality quizzes.
Learn about Our Editorial Process
| By Pratikjadhav
P
Pratikjadhav
Community Contributor
Quizzes Created: 1 | Total Attempts: 801
Questions: 50 | Attempts: 801

SettingsSettingsSettings
Blind Coding C Programming Practice Quiz! - Quiz

.


Questions and Answers
  • 1. 

    What will be the output of the program? #include #include int main() {     float n=1.54;     printf("%f, %f\n", ceil(n), floor(n));     return 0; }  

    • A.

      2.000000, 1.000000

    • B.

      1.500000, 1.500000

    • C.

      1.550000, 2.000000

    • D.

      1.000000, 2.000000

    Correct Answer
    A. 2.000000, 1.000000
    Explanation
    The program uses the ceil() and floor() functions to calculate the ceiling and floor values of the variable n, which is initialized as 1.54. The ceil() function returns the smallest integer that is greater than or equal to the given value, while the floor() function returns the largest integer that is less than or equal to the given value. In this case, the ceil() function will round up 1.54 to 2.000000, and the floor() function will round down 1.54 to 1.000000. Therefore, the output of the program will be "2.000000, 1.000000".

    Rate this question:

  • 2. 

    What will be the output of the program? #include int main() {     float d=2.25;     printf("%e,", d);     printf("%f,", d);     printf("%g,", d);     printf("%lf", d);     return 0; }  

    • A.

      2.2, 2.50, 2.50, 2.5

    • B.

      2.2e, 2.25f, 2.00, 2.25

    • C.

      2.250000e+000, 2.250000, 2.25, 2.250000

    • D.

      Error

    Correct Answer
    C. 2.250000e+000, 2.250000, 2.25, 2.250000
    Explanation
    The program will output the number "2.250000e+000" in scientific notation, followed by "2.250000" with six decimal places, then "2.25" in standard notation, and finally "2.250000" with six decimal places again. This is because the first printf statement uses the "%e" format specifier, which prints the number in scientific notation. The second printf statement uses the "%f" format specifier, which prints the number with six decimal places. The third printf statement uses the "%g" format specifier, which automatically chooses between scientific notation and standard notation depending on the magnitude of the number. The fourth printf statement uses the "%lf" format specifier, which is the same as "%f" but is used for double precision floating point numbers.

    Rate this question:

  • 3. 

    Point out the error in the program #include int main() {     int i;     #if A         printf("Enter any number:");         scanf("%d", &i);     #elif B         printf("The number is odd");     return 0; }  

    • A.

      Error: unexpected end of file because there is no matching #endif

    • B.

      The number is odd

    • C.

      Garbage values

    • D.

      None of above

    Correct Answer
    A. Error: unexpected end of file because there is no matching #endif
    Explanation
    The error in the program is that there is no matching #endif for the #if statement. This causes an unexpected end of file error.

    Rate this question:

  • 4. 

    What will be the output of the program (Turbo C in 16-bit platform DOS)? #include #include   int main() {     char *str1 = "India";     char *str2 = "BIX";     char *str3;     str3 = strcat(str1, str2);     printf("%s %s\n", str3, str1);     return 0; }  

    • A.

      IndiaBIX India

    • B.

      IndiaBIX IndiaBIX

    • C.

      India India

    • D.

      Error

    Correct Answer
    B. IndiaBIX IndiaBIX
    Explanation
    The program is using the strcat() function to concatenate str2 at the end of str1. However, str1 is a string literal and is stored in read-only memory. Trying to modify a string literal results in undefined behavior. In this case, it seems that the program is able to concatenate str2 with str1, but it is not guaranteed to work correctly. The output of the program is "IndiaBIX IndiaBIX", but it could have been different or even resulted in an error.

    Rate this question:

  • 5. 

    Which of the following statements correct about the below program? #include int main() {     union a     {         int i;         char ch[2];     };     union a u1 = {512};     union a u2 = {0, 2};     return 0; } 1:         u2 CANNOT be initialized as shown. 2:         u1 can be initialized as shown. 3:         To initialize char ch[] of u2 '.' operator should be used. 4:         The code causes an error 'Declaration syntax error'  

    • A.

      1, 2

    • B.

      2, 3

    • C.

      1, 2, 3

    • D.

      1, 3, 4

    Correct Answer
    C. 1, 2, 3
    Explanation
    1: u2 can be initialized as shown because it is a union and the initialization syntax used is valid.
    2: u1 can be initialized as shown because it is a union and the initialization syntax used is valid.
    3: To initialize char ch[] of u2, the '.' operator should be used instead of ',' operator.

    Rate this question:

  • 6. 

    What will be the output of the program? #include int get(); int main() {     const int x = get();     printf("%d", x);     return 0; } int get() {     return 20; }  

    • A.

      Garbage value

    • B.

      Error

    • C.

      20

    • D.

      0

    Correct Answer
    C. 20
    Explanation
    The program will output 20. This is because the function get() returns the value 20, which is then assigned to the constant variable x. When the value of x is printed using printf(), it will display 20.

    Rate this question:

  • 7. 

    Point out the error in the program.   #include   #include   int fun(const union employee *e);   union employee {     char name[15];     int age;     float salary; }; const union employee e1;   int main() {     strcpy(e1.name, "A");     fun(&e1);     printf("%s %d %f", e1.name, e1.age, e1.salary);     return 0; } int fun(const union employee *e) {     strcpy((*e).name, "B");     return 0; }  

    • A.

      Error: RValue required

    • B.

      Error: cannot convert parameter 1 from 'const char[15]' to 'char *'

    • C.

      Error: LValue required in strcpy

    • D.

      No error

    Correct Answer
    B. Error: cannot convert parameter 1 from 'const char[15]' to 'char *'
    Explanation
    The error in the program is that the function fun() is defined to take a pointer to a constant union employee as its parameter. However, in the main() function, the strcpy() function is used to modify the name of the e1 object, which is a violation of the const qualifier. This results in the error "cannot convert parameter 1 from 'const char[15]' to 'char *'".

    Rate this question:

  • 8. 

    Point out the error in the following program. #include void display(int (*ff)()); int main() {     int show();     int (*f)();     f = show;     display(f);     return 0; } void display(int (*ff)()) {     (*ff)(); } int show() {     printf("IndiaBIX"); }  

    • A.

      Error: invalid parameter in function display()

    • B.

      Error: invalid function call f=show;

    • C.

      No error and prints "IndiaBIX"

    • D.

      No error and prints nothing.

    Correct Answer
    C. No error and prints "IndiaBIX"
    Explanation
    The program does not have any errors and will print "IndiaBIX". The function display() takes a function pointer as a parameter and calls the function using the pointer. In the main() function, the function show() is declared and assigned to the function pointer f. The display() function is then called with the function pointer as an argument, which will execute the show() function and print "IndiaBIX".

    Rate this question:

  • 9. 

    Point out the error, if any in the program. #include int main() {     int a = 10, b;     a >=5 ? b=100: b=200;     printf("%d\n", b);     return 0; }  

    • A.

      100

    • B.

      200

    • C.

      Error: L value required for b

    • D.

      Garbage value

    Correct Answer
    C. Error: L value required for b
    Explanation
    The error in the program is that the ternary operator is trying to assign a value to a variable (b) that is not an l-value. An l-value refers to a location in memory that can be assigned a value. In this case, the ternary operator is trying to assign a value to b, but b does not have a memory location. To fix this error, the variable b should be declared before the ternary operator statement.

    Rate this question:

  • 10. 

    What will be the output of the program? #include int main() {     int i=4, j=-1, k=0, w, x, y, z;     w = i || j || k;     x = i && j && k;     y = i || j &&k;     z = i && j || k;     printf("%d, %d, %d, %d\n", w, x, y, z);     return 0; }  

    • A.

      1, 1, 1, 1

    • B.

      1, 1, 0, 1

    • C.

      1, 0, 0, 1

    • D.

      1, 0, 1, 1

    Correct Answer
    D. 1, 0, 1, 1
    Explanation
    The program first evaluates the logical OR operation between i, j, and k. Since i is non-zero, the result of this operation is 1.
    Next, the program evaluates the logical AND operation between i, j, and k. Since j is negative, the result of this operation is 0.
    Then, the program evaluates the logical OR operation between i and the logical AND operation between j and k. Since i is non-zero and j is negative, the result of this operation is 1.
    Finally, the program evaluates the logical AND operation between i and j, and then the logical OR operation between the result and k. Since i is non-zero and j is negative, the result of this operation is 1.
    Therefore, the output of the program is 1, 0, 1, 1.

    Rate this question:

  • 11. 

     Macros have a local scope.

    • A.

      True

    • B.

      False

    Correct Answer
    B. False
    Explanation
    Macros do not have a local scope. In programming, a local scope refers to a portion of code where variables and functions can only be accessed and used within that specific portion. However, macros are expanded by the preprocessor before the code is compiled, and they are not bound by any scope rules. Macros can be accessed and used throughout the entire program, making them have a global scope.

    Rate this question:

  • 12. 

    Is this a correct way for NULL pointer assignment? int i=0; char *q=(char*)i;  

    • A.

      Yes

    • B.

      No

    Correct Answer
    B. No
    Explanation
    No, this is not a correct way for NULL pointer assignment. In the given code, the variable "i" is of type int and it is being casted to a char pointer "q". This means that the value of "i" is being interpreted as a memory address, which is incorrect. A NULL pointer should be assigned using the literal value "NULL" or by assigning the address 0 to the pointer.

    Rate this question:

  • 13. 

    What will be the output of the program if the array begins at 65472 and each integer occupies 2 bytes? #include   int main() {     int a[3][4] = {1, 2, 3, 4, 4, 3, 2, 1, 7, 8, 9, 0};     printf("%u, %u\n", a+1, &a+1);     return 0; }  

    • A.

      65474, 65476

    • B.

      65480, 65496

    • C.

      65480, 65488

    • D.

      65474, 65488

    Correct Answer
    B. 65480, 65496
    Explanation
    The output of the program will be 65480, 65496.

    In the printf statement, we are printing the addresses of two different elements of the array.

    - The expression "a+1" gives the address of the second element of the array, which is a[1][0]. Since each integer occupies 2 bytes, the address of a[1][0] will be 65472 + (1 * 2) = 65474.

    - The expression "&a+1" gives the address of the next block of memory after the entire array. Since the array is a 3x4 matrix and each integer occupies 2 bytes, the size of the array is 3 * 4 * 2 = 24 bytes. Therefore, the address of the next block of memory will be 65472 + 24 = 65496.

    Rate this question:

  • 14. 

    What will be the output of the program ? #include #include   int main() {     char sentence[80];     int i;     printf("Enter a line of text\n");     gets(sentence);     for(i=strlen(sentence)-1; i >=0; i--)         putchar(sentence[i]);     return 0; }  

    • A.

      The sentence will get printed in same order as it entered

    • B.

      The sentence will get printed in reverse order

    • C.

      Half of the sentence will get printed

    • D.

      None of above

    Correct Answer
    B. The sentence will get printed in reverse order
    Explanation
    The program prompts the user to enter a line of text and stores it in the character array "sentence". It then uses a for loop to iterate through the characters in the array in reverse order, starting from the last character (strlen(sentence)-1) and ending at the first character (i >= 0). Inside the loop, each character is printed using the putchar function. Therefore, the output of the program will be the sentence entered by the user, but in reverse order.

    Rate this question:

  • 15. 

    What will be the output of the program ? #include       struct course     {         int courseno;         char coursename[25];     }; int main() {     struct course c[] = { {102, "Java"},                           {103, "pHP"},                           {104, "DotNet"}     };       printf("%d ", c[1].courseno);     printf("%s\n", (*(c+2)).coursename);     return 0; }  

    • A.

      103 DotNet

    • B.

      103 PHP

    • C.

      102 Java

    • D.

      104 DotNet

    Correct Answer
    A. 103 DotNet
    Explanation
    The program defines a structure called "course" with two members: courseno (an integer) and coursename (an array of characters). In the main function, an array of course structures called "c" is initialized with three elements, each containing a courseno and coursename.

    The first printf statement prints the courseno of the second element in the array, which is 103.

    The second printf statement prints the coursename of the third element in the array, using pointer arithmetic to access the member. It prints "DotNet", which is the coursename of the third element.

    So, the output of the program will be "103 DotNet".

    Rate this question:

  • 16. 

    On executing the below program what will be the contents of 'target.txt' file if the source file contains a line "To err is human"? #include   int main() {     int i, fss;     char ch, source[20] = "source.txt", target[20]="target.txt", t;     FILE *fs, *ft;     fs = fopen(source, "r");     ft = fopen(target, "w");     while(1)     {         ch=getc(fs);         if(ch==EOF)             break;         else         {             fseek(fs, 4L, SEEK_CUR);             fputc(ch, ft);         }     }     return 0; }  

    • A.

      R n

    • B.

      Trh

    • C.

      Err

    • D.

      None of above

    Correct Answer
    B. Trh
    Explanation
    The program opens a source file named "source.txt" and a target file named "target.txt". It then reads characters from the source file one by one using the getc() function. If the character is not the end of file (EOF), it moves the file pointer 4 positions ahead using fseek() and writes the character to the target file using fputc(). This process continues until the end of the source file is reached. Therefore, the contents of the "target.txt" file will be "Trh" which are the characters that were read and written from the source file.

    Rate this question:

  • 17. 

    What will be the output of the program (sample.c) given below if it is executed from the command line (Turbo C in DOS)? cmd> sample 1 2 3 /* sample.c */ #include   int main(int argc, char *argv[]) {     int j;     j = argv[1] + argv[2] + argv[3];     printf("%d", j);     return 0; }  

    • A.

      6

    • B.

      Sample 6

    • C.

      Error

    • D.

      Garbage value

    Correct Answer
    C. Error
    Explanation
    The program will output "Error". This is because the argv array stores command line arguments as strings, and the expression argv[1] + argv[2] + argv[3] is attempting to add three string pointers together, which is not a valid operation. Therefore, the program will result in a compilation error.

    Rate this question:

  • 18. 

    What will be the output of the program? #include int main() {     int x=1, y=1;     for(; y; printf("%d %d\n", x, y))     {         y = x++ <= 5;     }     printf("\n");     return 0; }  

    • A.

      A. 2 1 3 1 4 1 5 1 6 1 7 0

    • B.

      B. 2 1 3 1 4 1 5 1 6 1

    • C.

      C. 2 1 3 1 4 1 5 1

    • D.

      D. 2 2 3 3 4 4 5 5

    Correct Answer
    A. A. 2 1 3 1 4 1 5 1 6 1 7 0
    Explanation
    The program starts with initializing x and y to 1. The for loop has an empty initialization statement and the loop continues as long as y is non-zero. Inside the loop, the value of y is updated to the result of the comparison x++

    Rate this question:

  • 19. 

    Which of the following range is a valid long double (Turbo C in 16 bit DOS OS) ?  

    • A.

      3.4E-4932 to 1.1E+4932

    • B.

      3.4E-4932 to 3.4E+4932

    • C.

      1.1E-4932 to 1.1E+4932

    • D.

      1.7E-4932 to 1.7E+4932

    Correct Answer
    A. 3.4E-4932 to 1.1E+4932
    Explanation
    The correct answer is 3.4E-4932 to 1.1E+4932. This range represents the valid values for a long double data type in Turbo C in a 16-bit DOS operating system. The lower limit of 3.4E-4932 indicates the smallest possible positive value that can be stored, while the upper limit of 1.1E+4932 represents the largest possible positive value. Any value outside of this range would not be considered a valid long double in this specific context.

    Rate this question:

  • 20. 

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

    • A.

      Prints "IndiaBIX" 5 times

    • B.

      Function main() doesn't calls itself

    • C.

      Infinite loop

    • D.

      Prints "IndiaBIx"

    Correct Answer
    D. Prints "IndiaBIx"
    Explanation
    The program will enter the if statement and print "IndiaBIX" once. However, since the program calls the main function recursively, it will create an infinite loop and keep printing "IndiaBIX" indefinitely. Therefore, the correct answer is "Infinite loop".

    Rate this question:

  • 21. 

    What will be the output of the program ? #include   int main() {     int i, a[] = {2, 4, 6, 8, 10};     change(a, 5);     for(i=0; i<=4; i++)         printf("%d, ", a[i]);     return 0; } void change(int *b, int n) {     int i;     for(i=0; i        *(b+1) = *(b+i)+5; }            

    • A.

      7, 9, 11, 13, 15

    • B.

      2, 15, 6, 8, 10

    • C.

      2 4 6 8 10

    • D.

      3, 1, -1, -3, -5

    Correct Answer
    B. 2, 15, 6, 8, 10
    Explanation
    The program first declares an array "a" with 5 elements. Then, it calls the function "change" passing the array "a" and the size of the array as arguments. In the "change" function, it iterates over the elements of the array and assigns the value of each element to the next element plus 5. Finally, in the main function, it prints the elements of the array "a". The output of the program will be "2, 15, 6, 8, 10".

    Rate this question:

  • 22. 

    What will be the output of the program ? #include   int main() {     enum status {pass, fail, absent};     enum status stud1, stud2, stud3;     stud1 = pass;     stud2 = absent;     stud3 = fail;     printf("%d %d %d\n", stud1, stud2, stud3);     return 0; }  

    • A.

      0, 1, 2

    • B.

      1, 2, 3

    • C.

      0, 2, 1

    • D.

      1, 3, 2

    Correct Answer
    C. 0, 2, 1
    Explanation
    The program declares an enumeration type called "status" with three possible values: pass, fail, and absent. It then declares three variables of type "status" called stud1, stud2, and stud3. stud1 is assigned the value pass, stud2 is assigned the value absent, and stud3 is assigned the value fail. Finally, the program prints the values of stud1, stud2, and stud3, which are 0, 2, and 1 respectively.

    Rate this question:

  • 23. 

    Which of the following statements are correct about the program? #include char *fun(unsigned int num, int base);   int main() {     char *s;     s=fun(128, 2);     s=fun(128, 16);     printf("%s\n",s);     return 0; } char *fun(unsigned int num, int base) {     static char buff[33];     char *ptr = &buff[sizeof(buff)-1];     *ptr = '\0';     do     {         *--ptr = "0123456789abcdef"[num %base];         num /=base;     }while(num!=0);     return ptr; }  

    • A.

      It converts a number to a given base

    • B.

      It converts a number to its equivalent binary.

    • C.

      It converts a number to its equivalent hexadecimal.

    • D.

      It converts a number to its equivalent octal.

    Correct Answer
    A. It converts a number to a given base
    Explanation
    The program provided is a function called "fun" that takes a number and a base as input and converts the number to the given base. The function uses a static character array "buff" with a size of 33 to store the converted number. It then uses a pointer "ptr" to point to the last element of "buff" and assigns a null character '\0' to it. The function then uses a do-while loop to iterate through the number and convert it to the given base by using the remainder of the number divided by the base to access the corresponding character in the string "0123456789abcdef". The converted number is stored in reverse order in "buff". Finally, the function returns the pointer "ptr" which points to the converted number. Therefore, the correct answer is "It converts a number to a given base".

    Rate this question:

  • 24. 

    Point out the correct statement will let you access the elements of the array using 'p' in the following program? #include #include   int main() {     int i, j;     int(*p)[3];     p = (int(*)[3])malloc(3*sizeof(*p));     return 0; }  

    • A.

      For(i=0; i<3; i++) { for(j=0; j<3; j++) printf("%d", p[i+j]); }

    • B.

      For(i=0; i<3; i++) printf("%d", p[i]); C. for(i=0; i<3; i++) { for(j=0; j<3; j++) printf("%d", p[i][j]); }

    • C.

      For(i=0; i<3; i++) { for(j=0; j<3; j++) printf("%d", p[i][j]); }

    • D.

      For(j=0; j<3; j++) printf("%d", p[i][j]);

    Correct Answer
    C. For(i=0; i<3; i++) { for(j=0; j<3; j++) printf("%d", p[i][j]); }
    Explanation
    The correct statement that will let you access the elements of the array using 'p' in the given program is "for(i=0; i<3; i++)". This statement will iterate over the array 'p' and allow access to each element in the array.

    Rate this question:

  • 25. 

    Point out the error in the following program. #include #include   int main() {     char str1[] = "Learn through IndiaBIX\0.com",  str2[120];     char *p;     p = (char*) memccpy(str2, str1, 'i', strlen(str1));     *p = '\0';     printf("%s", str2);     return 0; }  

    • A.

      Error: in memccpy statement

    • B.

      Error: invalid pointer conversion

    • C.

      Error: invalid variable declaration

    • D.

      No error and prints "Learn through Indi"

    Correct Answer
    D. No error and prints "Learn through Indi"
    Explanation
    The program does not have any errors and it will print "Learn through Indi". The memccpy function is used to copy characters from one string to another until a specified character is encountered. In this program, the memccpy function is used to copy characters from str1 to str2 until the character 'i' is encountered. The pointer p is then assigned the value of the character 'i' in str2. Finally, the null character '\0' is added to the end of str2. The printf statement then prints the contents of str2, which is "Learn through Indi".

    Rate this question:

  • 26. 

    What does the following segment of code do?     fprintf(fp, “Copying!”);  

    • A.

      It writes “Copying!” into the file pointed by fp

    • B.

      It reads “Copying!” from the file and prints on display

    • C.

      It writes as well as reads “Copying!” to and from the file and prints it

    • D.

      None of the mentioned

    Correct Answer
    A. It writes “Copying!” into the file pointed by fp
    Explanation
    The given segment of code uses the fprintf function to write the string "Copying!" into the file pointed by the variable fp.

    Rate this question:

  • 27. 

    FILE reserved word is  

    • A.

      A structure tag declared in stdio.h

    • B.

      One of the basic datatypes in c

    • C.

      Pointer to the structure defined in stdio.h

    • D.

      It is a type name defined in stdio.h

    Correct Answer
    D. It is a type name defined in stdio.h
    Explanation
    The FILE reserved word is a type name defined in stdio.h. In C programming, FILE is used to declare objects that handle input and output operations. It represents the structure used to control streams in C, such as files. It provides functions and variables to perform operations like reading, writing, and manipulating files. By including stdio.h, the FILE type becomes available for use in the program.

    Rate this question:

  • 28. 

    What is the output of this C code?              #include              int main().             {.                 char *s = "myworld";                 int i = 9;                          printf("%*s", i, s);              }  

    • A.

      Myworld

    • B.

      Myworld(note: spaces to the left of myworld)

    • C.

      Myworld (note:followed by two spaces after myworld)

    • D.

      Undefined

    Correct Answer
    B. Myworld(note: spaces to the left of myworld)
    Explanation
    The code uses the printf function to print the string "myworld" with a specified width of 9 characters. The * in the format specifier %*s is used to specify the width as an argument. Since the width is set to 9, the output will have 9 characters. However, since the string "myworld" only has 7 characters, there will be 2 spaces added to the left of the string to fill the remaining width. Therefore, the output will be " myworld" with 2 spaces before "myworld".

    Rate this question:

  • 29. 

    What is the output of this C code?                 #include              int main()              {                  int i = 10;                  void *p = &i;                  printf("%f\n", *(float*)p);                  return 0;              }  

    • A.

      Compile time error

    • B.

      Undefined behaviour

    • C.

      10

    • D.

      0.000000

    Correct Answer
    D. 0.000000
    Explanation
    The code will result in undefined behavior. This is because the code is attempting to interpret the memory address of an integer variable as a float pointer and then dereference it to print the value. However, the memory layout and interpretation of the data will be different for an integer and a float, leading to unpredictable results.

    Rate this question:

  • 30. 

    What is the output of this C code?              #include .               int *i;.               int main()              {                  if (i == NULL)                      printf("true\n");                  return 0;              }  

    • A.

      true

    • B.

      True only if NULL value is 0

    • C.

      Compile time error

    • D.

      Nothing

    Correct Answer
    A. true
    Explanation
    The output of this C code is "true". This is because the variable "i" is not assigned any value, so it is uninitialized and its value is NULL. The if statement checks if "i" is equal to NULL, which is true in this case. Therefore, the code inside the if statement is executed and "true" is printed.

    Rate this question:

  • 31. 

    Which of the following declaration is illegal?

    • A.

      char *str = “Best C programming classes by Sanfoundry”;

    • B.

      char str[] = “Best C programming classes by Sanfoundry”;

    • C.

      Char str[20] = “Best C programming classes by Sanfoundry”;

    • D.

      Char[] str = “Best C programming classes by Sanfoundry”;

    Correct Answer
    D. Char[] str = “Best C programming classes by Sanfoundry”;
    Explanation
    The correct answer is "char[] str = “Best C programming classes by Sanfoundry”;". This declaration is illegal because when declaring an array, the size of the array must be specified. In this declaration, the size of the array is missing, which makes it invalid.

    Rate this question:

  • 32. 

    Comment on the output of this C code?       #include       struct temp       {           int a;           int b;           int c;       };       main()       {         struct temp p[] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};     }  

    • A.

      No Compile time error, generates an array of structure of size 3

    • B.

      No Compile time error, generates an array of structure of size 9

    • C.

      Compile time error, illegal declaration of a multidimensional array

    • D.

      Compile time error, illegal assignment to members of structure

    Correct Answer
    A. No Compile time error, generates an array of structure of size 3
    Explanation
    The given C code does not have any compile time errors and it generates an array of structure of size 3. The struct temp has three members: a, b, and c. The main function declares an array of struct temp called p and initializes it with three elements, each containing values for a, b, and c. Therefore, the code will compile successfully and create an array of structure of size 3.

    Rate this question:

  • 33. 

    What is the output of this C code?       #include       struct student       {       };       void main()       {           struct student s[2];           printf("%d", sizeof(s));       }  

    • A.

      2

    • B.

      4

    • C.

      8

    • D.

      0

    Correct Answer
    D. 0
    Explanation
    The code defines an empty structure called "student" and creates an array of two "student" objects called "s". The sizeof operator is then used to determine the size of the "s" array, which is 0. This is because the structure "student" has no members, so it does not occupy any memory. Therefore, the output of the code is 0.

    Rate this question:

  • 34. 

    What is the output of this C code?              #include              int *f();              int main()              {                  int *p = f();                  printf("%d\n", *p);              }              int *f()              {                int *j = (int*)malloc(sizeof(int));                 *j = 10;                 return j;             }  

    • A.

      10

    • B.

      Compile time error

    • C.

      Segmentation fault/runtime crash since pointer to local variable is returned

    • D.

      Undefined behaviour

    Correct Answer
    A. 10
    Explanation
    The output of this C code is 10. The function `f()` is called in the `main()` function and it returns a pointer to an integer. Inside the `f()` function, memory is allocated for an integer using `malloc()`, and the value 10 is assigned to it. This memory location is then returned and assigned to the pointer variable `p` in the `main()` function. The value of the integer pointed to by `p` is then printed, which is 10.

    Rate this question:

  • 35. 

    Which of the following causes an error?

    • A.

      Trying to read a file that doesn’t exist

    • B.

      Inability to write data in a file.

    • C.

      Failure to allocate memory with the help of malloc

    • D.

      All of the menioned

    Correct Answer
    D. All of the menioned
    Explanation
    All of the mentioned options can cause an error. Trying to read a file that doesn't exist will result in a file not found error. Inability to write data in a file can occur due to insufficient permissions or a full disk. Failure to allocate memory with malloc can lead to a memory allocation error, especially if there is not enough memory available. Therefore, all of these situations can cause errors.

    Rate this question:

  • 36. 

    What is the difference between %e and %g?

    • A.

      %e output formatting depends on the argument and %g always formats in the format [-]m.dddddd or [-]m.dddddE[+|-]xx where no.of ds are optional.

    • B.

      %e always formats in the format [-]m.dddddd or [-]m.dddddE[+|-]xx where no.of ds are optional and output formatting depends on the argument.

    • C.

      No differences

    • D.

      Depends on the standard

    Correct Answer
    B. %e always formats in the format [-]m.dddddd or [-]m.dddddE[+|-]xx where no.of ds are optional and output formatting depends on the argument.
    Explanation
    The correct answer is that %e always formats in the format [-]m.dddddd or [-]m.dddddE[+|-]xx where no.of ds are optional and output formatting depends on the argument. This means that %e will display the number in scientific notation, with the option to specify the number of decimal places. The output formatting will vary based on the argument provided.

    Rate this question:

  • 37. 

    What is the output of this C code(when 1 is entered)?     #include     void main()     {         double ch;         printf("enter a value btw 1 to 2:");         scanf("%lf", &ch);         switch (ch)         {         case 1:             printf("1");             break;         case 2:             printf("2");             break;         }     }

    • A.

      Compile time error

    • B.

      1

    • C.

      2

    • D.

      Varies

    Correct Answer
    A. Compile time error
    Explanation
    The code will result in a compile time error because the variable "ch" is declared as a double, but the switch statement only accepts integer values. Since the input is expected to be a decimal value between 1 and 2, it cannot be directly used in the switch statement.

    Rate this question:

  • 38. 

    What is the output of this C code(When 1 is entered)?     #include     void main()     {         char *ch;         printf("enter a value btw 1 to 3:");         scanf("%s", ch);         switch (ch)         {         case "1":             printf("1");             break;         case "2":             printf("2");             break;         }     }

    • A.

      1

    • B.

      Compile time error

    • C.

      2

    • D.

      Run time error

    Correct Answer
    B. Compile time error
    Explanation
    The code will result in a compile time error because the switch statement is comparing a char pointer (ch) with string literals ("1" and "2"). In C, string literals are represented as arrays of characters, so they cannot be directly compared with a char pointer. To fix this error, the code should use single quotes ('1' and '2') instead of double quotes when comparing characters.

    Rate this question:

  • 39. 

    What is the output of this C code?     #include     void main()     {         char *p = calloc(100, 1);         p = "welcome";         printf("%s\n", p);     }

    • A.

      Segmentation fault

    • B.

      Garbage

    • C.

      Error

    • D.

      Welcome

    Correct Answer
    D. Welcome
    Explanation
    The output of this C code is "welcome". The code first allocates memory of size 100 bytes using the calloc function and assigns the address of the allocated memory to the pointer variable p. However, the code then reassigns the pointer p to point to the string "welcome". So, when the printf function is called to print the value of p, it will print the string "welcome".

    Rate this question:

  • 40. 

    C preprocessors can have compiler specific features.

    • A.

      True

    • B.

      False

    • C.

      Depends on the standard

    • D.

      Depends on the platform

    Correct Answer
    A. True
    Explanation
    C preprocessors can have compiler specific features because preprocessors are part of the compiler and are responsible for performing text substitution before the actual compilation process begins. Different compilers may have their own specific features and extensions that can be used in the preprocessing stage. These features can include conditional compilation, macro expansion, and file inclusion, among others. Therefore, the statement is true.

    Rate this question:

  • 41. 

    What is the output of the code given below?     #include     int main()     {         printf("%d ", 1);         goto l1;         printf("%d ", 2);         l1:goto l2;         printf("%d ", 3);         l2:printf("%d ", 4);    }

    • A.

      1 4

    • B.

      Compilation error

    • C.

      1 2 4

    • D.

      1 3 4

    Correct Answer
    A. 1 4
    Explanation
    The code starts by printing "1" using the printf() function. Then, it encounters a goto statement which jumps to the label "l1". This means that the code after the goto statement is skipped. After jumping to "l1", it encounters another goto statement which jumps to the label "l2". Again, the code after this goto statement is skipped. Finally, it reaches the printf() statement which prints "4". Therefore, the output of the code is "1 4".

    Rate this question:

  • 42. 

    What is the output of this C code?     #include     const int a = 1,  b = 2;     int main()     {         int x = 1;         switch (x)         {         case a:             printf("yes ");         case b:             printf("no\n");             break;         }     }

    • A.

      Yes no

    • B.

      Yes

    • C.

      no

    • D.

      Compile time error

    Correct Answer
    D. Compile time error
    Explanation
    The code will result in a compile time error because the switch statement is using variables a and b as case values, which are declared as const. In C, the case values in a switch statement must be constant expressions, and variables declared as const do not qualify as constant expressions. Therefore, the code will not compile.

    Rate this question:

  • 43. 

    What is the output of this C code?     #include     int main()     {         int i = 0, j = 1;         int *a[] = {&i, &j};         printf("%d", *a[0]);         return 0;     }

    • A.

      Compile time error

    • B.

      Undefined behaviour

    • C.

      0

    • D.

      Some garbage value

    Correct Answer
    C. 0
    Explanation
    The output of this C code is 0. This is because the variable "a" is an array of pointers to integers, and it is initialized with the addresses of variables "i" and "j". When we access the value at index 0 of "a" using *a[0], it gives us the value stored at the address of "i", which is 0.

    Rate this question:

  • 44. 

    What is the output of this C code?     #include     void main()     {         struct student         {             int no;             char name[20];         };         struct student s;         s.no = 8;         printf("%d", s.no);     }

    • A.

      Nothing

    • B.

      Compile time error

    • C.

      Junk

    • D.

      8

    Correct Answer
    D. 8
    Explanation
    The code defines a structure named "student" with two members - "no" of type int and "name" of type char array. It then declares a variable "s" of type student. The value 8 is assigned to the "no" member of the "s" variable. Finally, the code prints the value of "s.no", which is 8. Therefore, the output of the code is 8.

    Rate this question:

  • 45. 

    Sin(x) returns

    • A.

      sine of x where x is in radians

    • B.

      Sine of x where x is in degree

    • C.

      Cosine of x where x is in radians

    • D.

      Cosine of x where x is in degree

    Correct Answer
    A. sine of x where x is in radians
    Explanation
    The function sin(x) returns the sine of x, where x is in radians. The sine function is a mathematical function that calculates the ratio of the length of the side opposite to an angle in a right triangle to the length of the hypotenuse. In this case, the function sin(x) calculates the sine of x when x is given in radians, which is the standard unit of measurement for angles in mathematics.

    Rate this question:

  • 46. 

    What is the output of this C code?     #include     int main()     {         int i = 0;         for (foo(); i == 1; i = 2)             printf("In for loop\n");             printf("After loop\n");     }     int foo()     {         return 1;     }

    • A.

      After loop

    • B.

      In for loop after loop

    • C.

      Compile time error

    • D.

      Infinite loop

    Correct Answer
    A. After loop
    Explanation
    The correct answer is "After loop". This is because the condition in the for loop is i == 1, but the initial value of i is 0. Therefore, the condition is false and the code inside the for loop is never executed. As a result, only the printf statement "After loop" is executed.

    Rate this question:

  • 47. 

    What is the output of this C code?     #include     void main()     {         int i = 0;         if (i == 0)         {             printf("Hello");             continue;         }     }

    • A.

      Hello is printed infinite times

    • B.

      Hello

    • C.

      Varies

    • D.

      Compile time error

    Correct Answer
    D. Compile time error
    Explanation
    The given code will result in a compile time error. The reason for this is that the "continue" statement is used outside of a loop. The "continue" statement is used to skip the rest of the current iteration of a loop and move to the next iteration. Since there is no loop present in the code, the "continue" statement is invalid and causes a compile time error.

    Rate this question:

  • 48. 

    What is the output of this C code?     #include     int main()     {         int x = 0;         if (x == 1)             if (x == 0)                 printf("inside if\n");             else                 printf("inside else if\n");         else             printf("inside else\n");     }

    • A.

      Inside if

    • B.

      Inside else if

    • C.

      Inside else

    • D.

      Compile time error

    Correct Answer
    C. Inside else
    Explanation
    The output of this C code is "inside else". This is because the value of x is 0, so the first if statement is not true. Therefore, the program moves to the else statement and prints "inside else".

    Rate this question:

  • 49. 

    What is the output of this C code?     #include     int main()     {         int x = 0;         if (x == 1)             if (x >= 0)                 printf("true\n");             else                 printf("false\n");     }

    • A.

      True

    • B.

      false

    • C.

      Depends on the compiler

    • D.

      No print statement

    Correct Answer
    D. No print statement
    Explanation
    The correct answer is "No print statement". This is because the if statement checks if x is equal to 1, and since x is initialized to 0, the condition is false. Therefore, the code inside the if statement is not executed, and there is no print statement in the code outside of the if statement.

    Rate this question:

  • 50. 

    C preprocessors can have compiler specific features.

    • A.

      True

    • B.

      False

    • C.

      Depends on the standard

    • D.

      Depends on the platform

    Correct Answer
    A. True
    Explanation
    C preprocessors can have compiler specific features because preprocessors are part of the compiler and can vary from compiler to compiler. These features may include compiler-specific directives, macros, or other functionalities that are not standardized across different compilers. Therefore, the availability and behavior of these features can depend on the specific compiler being used.

    Rate this question:

Quiz Review Timeline +

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

  • Current Version
  • Feb 06, 2024
    Quiz Edited by
    ProProfs Editorial Team
  • Aug 31, 2017
    Quiz Created by
    Pratikjadhav
Back to Top Back to top
Advertisement
×

Wait!
Here's an interesting quiz for you.

We have other quizzes matching your interest.