1. Question: Which of the following are unary operators in C? 1. ! 2. sizeof 3. ~ 4. &&

    A
    1, 2

    B
    1, 3

    C
    2, 4

    D
    1, 2, 3

    Note: An operation with only one operand is called unary operation. Unary operators: ! Logical NOT operator. ~ bitwise NOT operator. sizeof Size-of operator. && Logical AND is a logical operator. Therefore, 1, 2, 3 are unary operators.
    1. Report
  2. Question: In which order do the following gets evaluated 1. Relational 2. Arithmetic 3. Logical 4. Assignment

    A
    2134

    B
    1234

    C
    4321

    D
    3214

    Note: 2. Arithmetic operators: *, /, %, +, - 1. Relational operators: >, <, >=, <=, ==, != 3. Logical operators : !, &&, || 4. Assignment operators: =
    1. Report
  3. Question: What will the SWAP macro in the following program be expanded to on preprocessing? will the code compile?
    #include<stdio.h>
    #define SWAP(a, b, c)(c t; t=a, a=b, b=t)
    int main()
    {
        int x=10, y=20;
        SWAP(x, y, int);
        printf("%d %d\n", x, y);
        return 0;
    }

    A
    It compiles

    B
    Compiles with an warning

    C
    Not compile

    D
    Compiles and print nothing

    Note: The code won&#039;t compile since declaration of t cannot occur within parenthesis.
    1. Report
  4. Question: In which stage the following code #include&lt;stdio.h&gt; gets replaced by the contents of the file stdio.h

    A
    During editing

    B
    During linking

    C
    During execution

    D
    During preprocessing

    Note: The preprocessor replaces the line #include &lt;stdio.h&gt; with the system header file of that name. More precisely, the entire text of the file &#039;stdio.h&#039; replaces the #include directive.
    1. Report
  5. Question: Which of the following function sets first n characters of a string to a given character?

    A
    strinit()

    B
    strnset()

    C
    strset()

    D
    strcset()

    Note: char *strnset(char *s, int ch, size_t n); Sets the first n characters of s to ch
    #include &lt;stdio.h&gt;
    #include &lt;string.h&gt;
    
    int main(void)
    {
       char *string = &quot;abcdefghijklmnopqrstuvwxyz&quot;;
       char letter = &#039;x&#039;;
    
       printf(&quot;string before strnset: %s\n&quot;, string);
       strnset(string, letter, 13);
       printf(&quot;string after  strnset: %s\n&quot;, string);
    
       return 0;
    }
    Output: string before strnset: abcdefghijklmnopqrstuvwxyz string after strnset: xxxxxxxxxxxxxnopqrstuvwxyz
    1. Report
  6. Question: If the two strings are identical, then strcmp() function returns

    A
    -1

    B
    1

    C
    0

    D
    Yes

    Note: Declaration: strcmp(const char *s1, const char*s2); The strcmp return an int value that is if s1 &lt; s2 returns a value &lt; 0 if s1 == s2 returns 0 if s1 &gt; s2 returns a value &gt; 0
    1. Report
  7. Question: How will you print \n on the screen?

    A
    printf("\n");

    B
    echo "\\n";

    C
    printf('\n');

    D
    printf("\\n");

    Note: The statement printf("\\n"); prints '\n' on the screen.
    1. Report
  8. Question: The library function used to find the last occurrence of a character in a string is

    A
    strnstr()

    B
    aststr()

    C
    strrchr()

    D
    strnset()

    Note: he function strstr() Finds the first occurrence of a substring in another stringDeclaration: char *strstr(const char *s1, const char *s2);Return Value: On success, strstr returns a pointer to the element in s1 where s2 begins (points to s2 in s1). On error (if s2 does not occur in s1), strstr returns null.Example:
    #include <stdio.h>
    #include <string.h>
    
    int main(void)
    {
       char *str1 = "VCampus", *str2 = "mp", *ptr;
    
       ptr = strstr(str1, str2);
       printf("The substring is: %s\n", ptr);
       return 0;
    }
    Output: The substring is: mpus
    1. Report
  9. Question: Which of the following function is more appropriate for reading in a multi-word string?

    A
    printf();

    B
    scanf();

    C
    gets();

    D
    puts();

    Note: gets(); collects a string of characters terminated by a new line from the standard input stream stdin
    #include &lt;stdio.h&gt;
    
    int main(void)
    {
       char string[80];
    
       printf(&quot;Enter a string:&quot;);
       gets(string);
       printf(&quot;The string input was: %s\n&quot;, string);
       return 0;
    }
    Output: Enter a string: IndiaBIX The string input was: IndiaBIX
    1. Report
  10. Question: Which of the following function is correct that finds the length of a string?

    A
    int xstrlen(char *s)
    {
        int length=0;
        while(*s!='\0')
        {    length++; s++; }
        return (length);
    }

    B
    int xstrlen(char s)
    {
        int length=0;
        while(*s!='\0')
            length++; s++;
        return (length);
    }

    C
    int xstrlen(char *s)
    {
        int length=0;
        while(*s!='\0')
            length++;
        return (length);
    }

    D
    int xstrlen(char *s)
    {
        int length=0;
        while(*s!='\0')
            s++;
        return (length);
    }

    Note: Option A is the correct function to find the length of given string.Example:
    #include<stdio.h>
    
    int xstrlen(char *s)
    {
        int length=0;
        while(*s!='\0')
        { length++; s++; }
        return (length);
    }
    
    int main()
    {
        char d[] = "VCampus";
        printf("Length = %d\n", xstrlen(d));
        return 0;
    }
    1. Report
Copyright © 2024. Powered by Intellect Software Ltd