All Exams  >   Class 6  >   C Programming for Beginners  >   All Questions

All questions of C Tutorial for Class 6 Exam

What will be the output of the following C code?
    #include <stdio.h>
    void main()
    {
        int x = 1, y = 0, z = 5;
        int a = x && y && z++;
        printf("%d", z);
    }
  • a)
    6
  • b)
    5
  • c)
    0
  • d)
    Varies
Correct answer is option 'B'. Can you explain this answer?

Rutuja Bose answered
Explanation:

Initialization:
- Three integer variables x, y, and z are initialized to 1, 0, and 5 respectively.

Logical AND operator (&&):
- The logical AND operator (&&) evaluates from left to right. If the left operand is false, the right operand is not evaluated because the result will already be false.
- In this code, x is true (non-zero), y is false (zero), and z is true (non-zero).
- When the expression x && y && z++ is evaluated, since y is false (zero), the right side of the && operator (z++) is not evaluated.
- Therefore, z remains unchanged, and z will be 5 after the evaluation.

Output:
- The value of z is printed using printf function, which is 5.
Therefore, the output of the given code will be:

5

Which function will you choose to join two words?
  • a)
    strcpy()
  • b)
    strcat()
  • c)
    strncon()
  • d)
    memcon()
Correct answer is option 'B'. Can you explain this answer?

Sarita Singh answered
The strcat() function is used for concatenating two strings, appends a copy of the string.
char *strcat(char *s1,const char *s2);

What is the output of C Program.?
int main()
{
    int a=32;
    
    do
    {
        printf("%d ", a);
        a++;
    }while(a <= 30);
    return 0;
}
  • a)
    32
  • b)
    33
  • c)
    30
  • d)
    No Output
Correct answer is option 'A'. Can you explain this answer?

Jay Goyal answered
The code provided is incomplete. The printf statement is missing its closing quotation mark and the do-while loop does not have a closing brace. Additionally, there are no statements inside the loop.

Expand or Abbreviate ASCII with regard to C Language.
  • a)
    Australian Standard Code for Information Interchange
  • b)
    American Standard Code for Information Interchange
  • c)
    American Symbolic Code for Information Interchange
  • d)
    Australian Symbolic Code for Information Interchange
Correct answer is option 'B'. Can you explain this answer?

Shilpa Shah answered
ASCII stands for American Standard Code for Information Interchange. It is a character encoding standard that is widely used in computers and other electronic devices to represent text. ASCII uses a set of 128 standardized codes to represent characters, including letters, numbers, punctuation marks, and control characters.

The ASCII character set is based on the English alphabet and includes characters commonly used in the United States. However, ASCII does not include characters used in other languages or special symbols. This led to the development of other character encoding standards, such as Unicode, which supports a much larger set of characters.

Let's examine the given options and their relation to ASCII:

a) Australian Standard Code for Information Interchange:
This option is not correct. There is no such thing as the Australian Standard Code for Information Interchange. ASCII is an American standard and is not specific to any particular country.

b) American Standard Code for Information Interchange:
This option is correct. ASCII stands for American Standard Code for Information Interchange. It is the most commonly used character encoding standard in the United States and many other countries.

c) American Symbolic Code for Information Interchange:
This option is not correct. There is no such thing as the American Symbolic Code for Information Interchange. The correct term is American Standard Code for Information Interchange.

d) Australian Symbolic Code for Information Interchange:
This option is not correct. There is no such thing as the Australian Symbolic Code for Information Interchange. ASCII is an American standard and is not specific to any particular country.

In conclusion, the correct expansion of ASCII with regard to the C Language is "American Standard Code for Information Interchange". ASCII is a widely used character encoding standard that represents text using a set of 128 standardized codes.

What will be the output of the following C code?
    #include <stdio.h>
    int main()
    {
        int a = 10;
        double b = 5.6;
        int c;
        c = a + b;
        printf("%d", c);
    }
  • a)
    15
  • b)
    16
  • c)
    15.6
  • d)
    10
Correct answer is option 'A'. Can you explain this answer?

Understanding the Code
The provided C code snippet performs a simple arithmetic operation and prints the result. Let's break it down to understand the output.
Code Breakdown
- The code starts by including the standard input-output library with `#include `.
- Inside the `main` function, three variables are declared:
- `int a = 10;` (an integer)
- `double b = 5.6;` (a floating-point number)
- `int c;` (an integer that will store the result)
- The crucial line is `c = a + b;`. Here’s what happens:
- The integer `a` (10) is added to the double `b` (5.6).
- In C, when an integer is added to a floating-point number, the integer is implicitly converted to a double. Thus, the operation becomes: `10.0 (from a) + 5.6 = 15.6`.
Type Conversion
- The result `15.6` is a double, but `c` is declared as an integer.
- When assigning `15.6` to `c`, the decimal part is truncated (not rounded), so `c` will store only `15`.
Output of the Code
- The `printf` function is then called with the format specifier `%d`, which is used to print integers.
- Therefore, when `printf("%d", c);` executes, it prints the value of `c`, which is `15`.
Conclusion
- The final output of this code will indeed be `15`, making option 'A' the correct answer.

Use_______to determine the null-terminated message string that corresponds to the error code errcode.
  • a)
    strerror()
  • b)
    strstr()
  • c)
    strxfrm()
  • d)
    memset()
Correct answer is option 'A'. Can you explain this answer?

Anjali Sharma answered
Understanding the Correct Answer: strerror()
To determine the null-terminated message string that corresponds to an error code, the function you should use is `strerror()`. Here's why:
What is strerror()?
- `strerror()` is a standard C library function.
- It takes an error code (usually of type `int`) as an argument.
- The function returns a pointer to the string that describes the error code passed to it.
Why is it the Correct Choice?
- The primary purpose of `strerror()` is to convert error codes into human-readable strings.
- This is particularly useful for debugging or logging, as it provides meaningful error descriptions.
Other Options Explained
- strstr()
- This function is used for finding a substring within a string.
- It does not relate to error codes or messages.
- strxfrm()
- This function is used for transforming strings based on locale.
- It is not applicable for retrieving error messages.
- memset()
- This function is used to set a block of memory to a specific value.
- It does not relate to strings or error handling.
Conclusion
Using `strerror()` is essential for effectively converting error codes to descriptive strings, making it the correct answer for identifying error messages in programming.

The______ function returns the number of characters that are present before the terminating null character.
  • a)
    strlength()
  • b)
    strlen()
  • c)
    strlent()
  • d)
    strchr()
Correct answer is option 'B'. Can you explain this answer?

Sarita Singh answered
The strlen() function is used to return the number of characters that are present before the terminating null character.size-t strlen(const char *s);The length of the string pointed to by s is computed by strlen().

What will be the output of the following C code?
    #include <stdio.h>
    #define MAX 2
    enum bird {SPARROW = MAX + 1, PARROT = SPARROW + MAX};
    int main()
    {
        enum bird b = PARROT;
        printf("%d\n", b);
        return 0;
    }
  • a)
    Compilation error
  • b)
    5
  • c)
    Undefined value
  • d)
    2
Correct answer is option 'B'. Can you explain this answer?

Mahesh Chavan answered


Explanation:

Enum Declaration:
- The enum `bird` is declared with two constants: `SPARROW` and `PARROT`.
- The value of `SPARROW` is defined as `MAX + 1`, where `MAX` is defined as 2.
- The value of `PARROT` is defined as `SPARROW + MAX`.

Main Function:
- In the `main` function, a variable `b` of type `enum bird` is declared and initialized with the value `PARROT`.

Output:
- The value of `PARROT` is calculated as `SPARROW + MAX`.
- Substituting the values, `SPARROW` is `MAX + 1` (which is 3) and `MAX` is 2.
- Therefore, `PARROT` is calculated as `3 + 2` which equals `5`.
- The printf statement then prints the value of `b` which is `5`.

Therefore, the output of the code will be:


5

What will be the output of the following C code?
    #include <stdio.h>
    int main()
    {
        printf("sanfoundry\rclass\n");
        return 0;
    }
  • a)
    sanfoundryclass
  • b)
    sanfoundry
    class
  • c)
    classundry
  • d)
    sanfoundry
Correct answer is option 'C'. Can you explain this answer?

Understanding the Code
The provided C code snippet is:
c
#include
int main() {
printf("sanfoundry\rclass\n");
return 0;
}
Key Elements of the Code
- Header Inclusion: The code includes the standard input-output library `` which is necessary for using the `printf` function.
- Main Function: The `main` function is the entry point of the program.
- Printf Function: The `printf` function is used to print formatted output to the console.
Escape Sequences
- \r (Carriage Return): This escape sequence moves the cursor back to the beginning of the line without advancing to the next line.
- \n (New Line): This escape sequence advances the cursor to the next line after printing the output.
Execution Flow
1. The string "sanfoundry" is printed first.
2. The `\r` escape sequence then moves the cursor back to the start of the line.
3. Next, "class" is printed, overwriting the beginning of "sanfoundry" due to the carriage return.
4. Finally, `\n` moves the cursor to the next line.
Final Output Explanation
- The output will display as follows:
classundry
Here, "class" overwrites the "sanf" part of "sanfoundry", resulting in "classundry" being printed.
Correct Option
Thus, the correct answer is option 'C': classundry.

What will be the output of the following C code?
    #include <stdio.h>
    void main()
    {
        int k = 4;
        int *const p = &k;
        int r = 3;
        p = &r;
        printf("%d", p);
    }
  • a)
    Address of k
  • b)
    Address of r
  • c)
    Compile time error
  • d)
    Address of k + address of r
Correct answer is option 'C'. Can you explain this answer?

Anand Patel answered
Explanation:
- Constant Pointer:
- In the given code, a constant pointer p is declared with the value of k.
- The pointer p is declared as a constant, meaning that it cannot be reassigned to point to a different memory location.
- Assignment Error:
- The statement p = &r; tries to assign the address of variable r to the constant pointer p.
- This will result in a compile-time error because constant pointers cannot be reassigned after initialization.
- Compile Time Error:
- Due to the attempt to assign a new address to the constant pointer p, the code will not compile successfully.
- The compiler will generate an error indicating that the assignment to a constant pointer is not allowed.
Therefore, the correct output of the code will be a Compile Time Error.

What is the output of C Program with switch statement or block?
  • a)
    ZERO FIVE DEER LION
  • b)
    FIVE DEER LION
  • c)
    FIVE LION
  • d)
    Compiler error
Correct answer is option 'C'. Can you explain this answer?

Sarita Singh answered
After matching 5, FIVE will be printed. BREAK causes control to exit SWITCH immediately. Also, using a STATIC variable is also allowed.

Choose a correct statement about C language break; statement.
  • a)
    A single break; statement can force execution control to come out of only one loop.
  • b)
    A single break; statement can force execution control to come out of a maximum of two nested loops.
  • c)
    A single break; statement can force execution control to come out of a maximum of three nested loops.
  • d)
    None of the above.
Correct answer is option 'A'. Can you explain this answer?

Dr Manju Sen answered
The correct statement is:
1. A single break; statement can force execution control to come out of only one loop.
Explanation:
  • In C language, a break; statement is used to exit the nearest enclosing loop (or switch statement) in which it is placed. It does not affect any outer loops if there are nested loops. Therefore, a single break; statement only forces the control to exit the innermost loop.

What will be the output of the following C code?
    #include <stdio.h>
    int main()
    {
        printf("C programming %s", "Class by\n%s Sanfoundry", "WOW");
    }
  • a)
    C programming Class by
    WOW Sanfoundry
  • b)
    C programming Class by\n%s Sanfoundry
  • c)
    C programming Class by
    %s Sanfoundry
  • d)
    Compilation error
Correct answer is option 'C'. Can you explain this answer?

Explanation:
- The code snippet provided is trying to print a formatted string using the `printf` function.
- The format string given is "C programming %s", which contains one placeholder for a string.
- However, in the `printf` statement, there are three arguments provided.
- The first argument is the format string "C programming %s".
- The second argument is the string "Class by\n%s Sanfoundry".
- The third argument is the string "WOW".
- Since there is no placeholder in the format string for the third argument, it will be ignored by the `printf` function.
- So, the output will be "C programming Class by%s Sanfoundry".
Therefore, the correct output will be:
C programming Class by%s Sanfoundry

Which of the given function is used to return a pointer to the located character?
  • a)
    strrchr()
  • b)
    strxfrm()
  • c)
    memchar()
  • d)
    strchar()
Correct answer is option 'D'. Can you explain this answer?

Neha Mehta answered
The correct answer is option 'A' (strrchr()) and not option 'D' (strchar()).
- The function strrchr() is used to return a pointer to the last occurrence of a specific character in a given string.
- This function takes two arguments: a pointer to the string in which to search for the character, and the character to be located.
- The function starts from the end of the string and searches backwards until it finds the specified character or reaches the beginning of the string.
- If the character is found, the function returns a pointer to that character in the string. If the character is not found, the function returns a null pointer.

Here is an example usage of strrchr():

```c
#include
#include

int main() {
char str[] = "Hello, world!";
char ch = 'o';
char* ptr = strrchr(str, ch);

if (ptr != NULL) {
printf("Character '%c' found at position: %ld\n", ch, ptr - str);
} else {
printf("Character '%c' not found in the string.\n", ch);
}

return 0;
}
```

In the above example, the strrchr() function is used to search for the last occurrence of the character 'o' in the string "Hello, world!". Since the last occurrence of 'o' is at position 8, the function returns a pointer to that position. The program then prints the position as output.

Therefore, the correct answer is option 'A' (strrchr()).

What is the output of C Program.?
int main()
{
    int k, j;
    
    for(k=1, j=10; k <= 5; k++)
    {
        printf("%d ", (k+j));
    }
    return 0;
}
  • a)
    compiler error
  • b)
    10 10 10 10 10
  • c)
    11 12 13 14 15
  • d)
    None of the above
Correct answer is option 'C'. Can you explain this answer?

There is an error in the code. The condition of the for loop is incomplete. It should be "k < j"="" or="" "k="" /><= j"="" or="" "k=""> j" or "k >= j". Without a proper condition, the program cannot compile or run.

What will be the output of the following C code?
    #include <stdio.h>
    int main()
    {
        int i = 3;
        int l = i / -2;
        int k = i % -2;
        printf("%d %d\n", l, k);
        return 0;
    }
  • a)
    Compile time error
  • b)
     -1 1
  • c)
    1 -1
  • d)
    Implementation defined
Correct answer is option 'B'. Can you explain this answer?

Rounak Patel answered
Understanding the Code
The provided C code performs basic arithmetic operations involving division and modulus with negative numbers. Let's break down the code step-by-step.
Code Analysis
- The variable `i` is initialized to 3.
- The division operation `i / -2` is computed next:
- In C, when dividing an integer by a negative integer, the result is floored. Thus, `3 / -2` results in `-1`.
- Next, the modulus operation `i % -2` is evaluated:
- The result of the modulus operation takes the sign of the divisor. Therefore, `3 % -2` results in `1`.
Expected Output
- Finally, the `printf` function outputs the values of `l` and `k`:
- `l` is `-1` and `k` is `1`.
Thus, the output from the `printf` statement will be:
-1 1
Conclusion
The correct answer to the question is option 'B', which outputs `-1 1`. This is due to the specific rules of integer division and modulus in C when negative integers are involved.

What will be the output of the following C code?
    #include <stdio.h>
    void main()
    {
        int const k = 5;
        k++;
        printf("k is %d", k);
    }
  • a)
    k is 6
  • b)
    Error due to const succeeding int
  • c)
    Error, because a constant variable can be changed only twice
  • d)
    Error, because a constant variable cannot be changed
Correct answer is option 'D'. Can you explain this answer?

Kiran Das answered
Understanding the C Code
The provided C code snippet contains a few key elements that lead to its output. Let's break it down:
Code Analysis
- The code begins by including the standard input-output library using `#include `.
- The `main` function is defined as `void main()`, which is technically incorrect in standard C but is accepted by some compilers.
- Inside the function, a constant integer `k` is declared and initialized with the value `5` using `int const k = 5;`.
Key Point: Constant Variable
- A variable declared with `const` means that it is read-only and cannot be modified after its initialization.
- The statement `k++;` attempts to increment the value of `k`, which violates the rules of constant variables.
Expected Output and Errors
- Since `k` is a constant, the line `k++;` will generate a compile-time error.
- The compiler will notify that you cannot change the value of a constant variable.
Conclusion
- Therefore, the correct answer is option 'D': "Error, because a constant variable cannot be changed."
- The program will not compile successfully due to the attempt to modify a constant variable.
Understanding these principles will help you grasp the importance of constant variables in C programming.

Which of the following statement is false?
  • a)
    Constant variables need not be defined as they are declared and can be defined later
  • b)
    Global constant variables are initialized to zero
  • c)
    const keyword is used to define constant values
  • d)
    You cannot reassign a value to a constant variable
Correct answer is option 'A'. Can you explain this answer?

Palak Nair answered
False Statement: a) Constant variables need not be defined as they are declared and can be defined later.

Explanation:
Constants are variables whose values cannot be changed once they are assigned. In most programming languages, constant variables need to be defined at the time of declaration and cannot be defined later. Therefore, statement a) is false.

Detailed Explanation:
1. Constant Variables:
- Constant variables are variables whose values remain the same throughout the program.
- They are declared using the const keyword.
- The value assigned to a constant variable cannot be modified once it is assigned.

2. Defining Constant Variables:
- Constant variables need to be defined at the time of declaration.
- They cannot be defined later in the program.
- Once a constant variable is declared and defined, its value remains constant throughout the program execution.

3. False Statement Explanation:
- Statement a) states that constant variables need not be defined as they are declared and can be defined later.
- However, this statement is incorrect.
- Constant variables require definition at the time of declaration, and their values cannot be changed later.
- If a constant variable is declared without a definition, it will result in a compilation error.

4. Correct Statements:
- b) Global constant variables are initialized to zero.
- Global constant variables, which are declared outside any function, are automatically initialized to zero if no initial value is specified.
- c) const keyword is used to define constant values.
- The const keyword is used to declare and define constant variables in programming languages.
- d) You cannot reassign a value to a constant variable.
- Once a value is assigned to a constant variable, it cannot be modified or reassigned throughout the program.

Conclusion:
Constant variables need to be defined at the time of declaration and cannot be defined later. Therefore, option 'a' is the false statement among the given options.

What is the output of C Program?
int main()
{
    int a=5;
    
    while(a==5)    
    {
        printf("RABBIT");
        break;
    }
    return 0;
}
  • a)
    RABBIT is printed unlimited number of times
  • b)
    RABBIT
  • c)
    Compiler error
  • d)
    None of the above.
Correct answer is option 'B'. Can you explain this answer?

Bijoy Goyal answered
"Hello World\n"); } return 0; }

The output of this program is "Hello World" printed repeatedly in an infinite loop because the condition of the while loop (a == 5) will always be true since the value of a is never changed within the loop.

Which of the following function returns a pointer to the located string or a null pointer if string is not found.
  • a)
    strtok()
  • b)
    strstr()
  • c)
    strspn()
  • d)
    strrchr()
Correct answer is option 'B'. Can you explain this answer?

Harshad Goyal answered
Understanding the Function: strstr()
The correct answer is option 'B', `strstr()`. This function is part of the C standard library and is used for string manipulation.
What does strstr() do?
- `strstr()` searches for a substring within a larger string.
- It takes two parameters: the main string and the substring to search for.
- If the substring is found, it returns a pointer to the first occurrence of the substring in the main string.
- If the substring is not found, it returns a null pointer.
Why is strstr() the correct choice?
- The primary purpose of `strstr()` is to locate a substring.
- Its behavior of returning a pointer (or null) aligns perfectly with the question's requirement.
- Other functions listed do not fulfill this specific criterion.
Comparison with Other Options:
- strtok(): This function is used for tokenizing strings, not for searching substrings.
- strspn(): This function calculates the length of the initial segment of a string that consists only of characters from a specified set. It does not return a pointer to a substring.
- strrchr(): This function locates the last occurrence of a character in a string, not a substring.
Conclusion
In conclusion, `strstr()` is the correct function to use when you need to find a substring within a string and receive a pointer to its location, making it the best choice among the options provided.

What is the way to suddenly come out of or Quit any Loop in C Language?
  • a)
    continue; statement
  • b)
    break; statement
  • c)
    leave; statement
  • d)
    quit; statement
Correct answer is option 'B'. Can you explain this answer?

Saikat Pillai answered
Understanding the 'break' Statement in C
The 'break' statement is a powerful tool in C programming that allows you to exit from loops and switch statements prematurely. Here’s a detailed look at how it works.
What Does the 'break' Statement Do?
- The 'break' statement is used to terminate the closest enclosing loop (for, while, or do-while) or switch statement.
- When the 'break' statement is executed, control jumps to the statement immediately following the loop or switch.
How to Use the 'break' Statement
- It is often used in scenarios where a certain condition is met, and continuing the loop is unnecessary or undesirable.
Example:
c
for (int i = 0; i < 10;="" i++)="" />
if (i == 5) {
break; // Exit the loop when i equals 5
}
printf("%d ", i);
}
- In this example, the loop will print numbers from 0 to 4 and then exit when 'i' equals 5.
Comparing with Other Statements
- continue: Skips the current iteration but does not exit the loop. It goes to the next iteration.
- leave & quit: These are not valid statements in C. They will cause a compilation error.
Conclusion
The correct way to exit a loop in C is by using the 'break' statement, making it an essential part of controlling loop execution effectively.

What is the output of C Program with switch statement or block.?
int main()
{
    int k=8;
    
    switch(k)
    {
        case 1==8: printf("ROSE ");break;
        case 1 && 2: printf("JASMINE "); break;
        default: printf("FLOWER ");
    }
    
    printf("GARDEN");
}
  • a)
    ROSE GARGEN
  • b)
    JASMINE GARDEN
  • c)
    FLOWER GARDEN
  • d)
    Compiler error
Correct answer is option 'C'. Can you explain this answer?

Maya Mehta answered
Explanation:
Switch statement in C programming language allows you to choose one case from multiple options. In this code snippet, the switch statement is used to check the value of variable 'k'.
- Case 1==8: Here, the case expression is '1==8', which evaluates to false (0). Since the switch statement checks for equality, it will not match this case.
- Case 1 && 2: In this case, the expression '1 && 2' evaluates to true (1). However, switch case does not evaluate logical expressions, so it will not match this case either.
- Default: Since none of the cases match, the default case will be executed. It will print "FLOWER ".
- After the switch statement, "GARDEN" is printed outside the switch block.
Therefore, the output of the program will be "FLOWER GARDEN".

What is the output of C program with switch statement or block?
int main()
{
    char code='K';
    
    switch(code)
    {
        case 'A': printf("ANT ");break;
        case 'K': printf("KING "); break;
        default: printf("NOKING");
    }
    
    printf("PALACE");
}
  • a)
    KING PALACE
  • b)
    KING NOTHING PALACE
  • c)
    ANT KING PALACE
  • d)
    Compiler error for using Non Integers as CASE constants.
Correct answer is option 'A'. Can you explain this answer?

Varun Jain answered
The code you provided is incomplete and contains errors. Here is the corrected version:

```c
#include

int main() {
char code = 'K';

switch(code) {
case 'A':
printf("Code is A\n");
break;
case 'B':
printf("Code is B\n");
break;
default:
printf("Code is not A or B\n");
}

return 0;
}
```

The output of this program will be:

```
Code is not A or B
```

Choose a correct statement about C break; statement.?
  • a)
    break; statement can be used inside switch block
  • b)
    break; statement can be used with loops like for, while and do while.
  • c)
    break; statement causes only the same or inner loop where break; is present to quit suddenly.
  • d)
    All the above.
Correct answer is option 'D'. Can you explain this answer?

Ashutosh Verma answered
Explanation:
The break; statement is used in programming languages like C to exit or terminate a loop or switch statement. It is commonly used when a certain condition is met and the program needs to exit the loop or switch statement.

The correct statement about the break; statement is option 'd', which states that it can be used in all of the mentioned cases. Let's discuss each of these cases in detail:

1. break; statement inside switch block:
The break; statement is commonly used inside a switch block to exit the switch statement and prevent the execution of subsequent cases. When the break; statement is encountered inside a switch case, the control is transferred to the end of the switch block.

Example:
```
switch (choice) {
case 1:
// code for case 1
break;
case 2:
// code for case 2
break;
default:
// code for default case
break;
}
```

2. break; statement with loops:
The break; statement can also be used with loops like for, while, and do while. When the break; statement is encountered inside a loop, it immediately terminates the loop and transfers the control to the statement following the loop.

Example:
```
for (int i = 0; i < 10;="" i++)="" />
if (i == 5) {
break; // terminate the loop when i is 5
}
printf("%d ", i);
}
```
Output: 0 1 2 3 4

3. break; statement and loop termination:
The break; statement causes only the same or inner loop where break; is present to quit suddenly. It does not affect the outer loops. This means that if there are nested loops, the break; statement will only terminate the loop in which it is present, and the program will continue with the outer loops.

Example:
```
for (int i = 0; i < 5;="" i++)="" />
for (int j = 0; j < 3;="" j++)="" />
if (j == 1) {
break; // terminate the inner loop when j is 1
}
printf("%d %d ", i, j);
}
}
```
Output: 0 0 1 0 2 0 3 0 4 0

In the above example, the inner loop terminates when j is 1, but the outer loop continues until its condition is met.

In conclusion, the break; statement can be used inside a switch block, with loops like for, while, and do while, and it causes only the same or inner loop where it is present to quit suddenly.

What will be the output of the following C code?
    #include <stdio.h>
    int main()
    {
        const int p;
        p = 4;
        printf("p is %d", p);
        return 0;
    }
  • a)
    p is 4
  • b)
    Compile time error
  • c)
    Run time error
  • d)
    p is followed by a garbage value
Correct answer is option 'B'. Can you explain this answer?

Puja Chopra answered
Explanation:
The code will result in a compile time error because the variable `p` is declared as a constant using the `const` keyword but is then assigned a value of 4. This is not allowed because a constant variable cannot be modified after initialization.

Reason:
- The variable `p` is declared as a constant using the `const` keyword, making it read-only.
- The assignment `p = 4;` tries to modify the value of `p`, which is not allowed for constant variables.
- This violation of the constant variable rule will result in a compile time error.
Therefore, the output of the code will be a compile time error.

What is the prototype of strcoll() function?
  • a)
    int strcoll(const char *s1,const char *s2)
  • b)
    int strcoll(const char *s1)
  • c)
    int strcoll(const *s1,const *s2)
  • d)
    int strcoll(const *s1)
Correct answer is option 'A'. Can you explain this answer?

Ashutosh Verma answered
Prototype of strcoll() function:
The prototype of the strcoll() function is:
a) int strcoll(const char *s1, const char *s2)

Explanation:
The strcoll() function is used to compare two strings based on the current locale. It compares the strings s1 and s2 and returns an integer value indicating the ordering of the strings.

Let's break down the prototype of the strcoll() function:

1. Return Type: The return type of the strcoll() function is 'int', which represents an integer value indicating the ordering of the strings.

2. Parameters: The strcoll() function takes two parameters:
- s1: It is a pointer to the first string to be compared.
- s2: It is a pointer to the second string to be compared.

Both s1 and s2 are of type 'const char *', which means they are constant pointers to characters. This implies that the function does not modify the contents of the strings.

The strcoll() function compares the strings s1 and s2 by considering the current locale. It takes into account the language-specific collation rules, which define the sorting order of characters in different languages. The function returns an integer value that indicates the ordering of the strings based on the collation rules.

The return value of the strcoll() function can have three possible meanings:
- If the return value is less than 0, it means s1 is less than s2.
- If the return value is greater than 0, it means s1 is greater than s2.
- If the return value is 0, it means s1 is equal to s2.

The strcoll() function is useful when sorting strings in a locale-specific manner, where the sorting order may differ based on the language or cultural conventions.

Chapter doubts & questions for C Tutorial - C Programming for Beginners 2025 is part of Class 6 exam preparation. The chapters have been prepared according to the Class 6 exam syllabus. The Chapter doubts & questions, notes, tests & MCQs are made for Class 6 2025 Exam. Find important definitions, questions, notes, meanings, examples, exercises, MCQs and online tests here.

Chapter doubts & questions of C Tutorial - C Programming for Beginners in English & Hindi are available as part of Class 6 exam. Download more important topics, notes, lectures and mock test series for Class 6 Exam by signing up for free.

Signup to see your scores go up within 7 days!

Study with 1000+ FREE Docs, Videos & Tests
10M+ students study on EduRev