Friday, 10 November 2017

Strings Questions in C

-------------------------------------------------------------------------------------------------------------
Previous Page            Next Page                Last Page
-------------------------------------------------------------------------------------------------------------

11.
If the size of pointer is 4 bytes then What will be the output of the program ?

#include

int main()
{
    char *str[] = {"Frogs", "Do", "Not", "Die", "They", "Croak!"};
    printf("%d, %d", sizeof(str), strlen(str[0]));
    return 0;
}

A. 22, 4
B. 25, 5
C. 24, 5
D. 20, 2

Answer: C
---------------------------------------------------------------------------------------------------------------

12.
What will be the output of the program ?

#include
#include

int main()
{
    char str1[5], str2[5];
    int i;
    gets(str1);
    gets(str2);
    i = strcmp(str1, str2);
    printf("%d\n", i);
    return 0;
}

A. Unpredictable integer value
B. 0
C. -1
D. Error

Answer: A
-------------------------------------------------------------------------------------------------------------

13.
What will be the output of the program ?

#include
int main()
{
    char str = "ExecuteCodes";
    printf("%s\n", str);
    return 0;
}

A. Error
B. ExecuteCodes
C. Base address of str
D. No output

Answer: A
------------------------------------------------------------------------------------------------------------

14.
What will be the output of the program ?

#include
int main()
{
    char str[] = "Nagpur";
    str[0]='K';
    printf("%s, ", str);
    str = "Kanpur";
    printf("%s", str+1);
    return 0;
}

A. Kagpur, Kanpur
B. Nagpur, Kanpur
C. Kagpur, anpur
D. Error

Answer: D
-----------------------------------------------------------------------------------------------------------
Previous Page                   Next Page               Last Page
-----------------------------------------------------------------------------------------------------------

More Imp Topics:

Array
Preprocessor
Structures
Control Structures
Switch Case
Printf
Variables
File Handling


100+ Best Home Decoration Ideas For Christmas Day 2019 To Make Home Beautiful

Best gifts for Christmas Day | Greeting cards for Christmas Day | Gift your children a new gift on Christmas day This Christmas d...