C Programming

C Programming

Strings has 50 Questions

Which of the following function sets first n characters of a string to a given character?

strinit()
strnset()
strset()
strcset()
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", strcpy(str2, strcat(str1, str2)));
    return 0;
}

Hello
World
Hello World
WorldHello
Which of the following statements are correct about the program below?
#include<stdio.h>

int main()
{
    char str[20], *s;
    printf("Enter a string");
    scanf("%s", str);
    s=str;
    while(*s != '')
    {
        if(*s >= 97 && *s <= 122)
            *s = *s-32;
        s++;
    }
    printf("%s",str);
    return 0;
}

The code converts a string in to an integer
The code converts lower case character to upper case
The code converts upper case character to lower case
Error in code
Will the program compile successfully?
#include<stdio.h>

int main()
{
    char a[] = "Astiwz";
    char *p = "QUIZ";
    a = "QUIZ";
    p = "Astiwz";
    printf("%s %s", a, p);
    return 0;
}

Yes
No
The library function used to reverse a string is

strstr()
strrev()
revstr()
strreverse()
What will be the output of the program ?
#include<stdio.h>

int main()
{
    char p[] = "%d";
    p[1] = 'c';
    printf(p, 65);
    return 0;
}

A
a
c
65
Which of the following statements are correct about the below declarations?
char *p = "Sanjay";
char a[] = "Sanjay";
1: There is no difference in the declarations and both serve the same purpose.
2: p is a non-const pointer pointing to a non-const string, whereas a is a const pointer pointing to a non-const pointer.
3: The pointer p can be modified to point to another string, whereas the individual characters within array a can be changed.
4: In both cases the '' will be added at the end of the string "Sanjay".

1, 2
2, 3, 4
3, 4
2, 3
For the following statements will arr[3] and ptr[3] fetch the same character?
char arr[] = "ASTIWZ";
char *ptr = "ASTIWZ";

Yes
No
If the two strings are identical, then strcmp() function returns

-1
1
0
Yes
What will be the output of the program ?
#include<stdio.h>
#include<string.h>

int main()
{
    printf("%d", strlen("123456"));
    return 0;
}

6
12
7
2
Which of the following statements are correct ?
1: A string is a collection of characters terminated by ''.
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.

A, B
A, B, C
B, D
C, D
Is there any difference between the two statements?
char *ch = "ASTIWZ";
char ch[] = "ASTIWZ";

Yes
No
How will you print on the screen?

printf("");
echo "";
printf('');
printf("");
What will be the output of the program ?
#include<stdio.h>

int main()
{
    printf(5+"Good Morning");
    return 0;
}

Good Morning
Good
M
Morning
Which of the following statement is correct?

strcmp(s1, s2) returns a number less than 0 if s1>s2
strcmp(s1, s2) returns a number greater than 0 if s1<s2
strcmp(s1, s2) returns 0 if s1==s2
strcmp(s1, s2) returns 1 if s1==s2
The library function used to find the last occurrence of a character in a string is

strnstr()
laststr()
strrchr()
strstr()
What will be the output of the program ?
#include
#include

int main()
{
    char str[] = "AstiwzQUIZ";
    printf("%s", str);
    return 0;
}

QUIZ
Astiwz
Astiwz QUIZ
Astiwz QUIZ
Which of the following function is used to find the first occurrence of a given string in another string?

strchr()
strrchr()
strstr()
strnset()
What will be the output of the program If characters 'a', 'b' and 'c' enter are supplied as input?
#include<stdio.h>

int main()
{
    void fun();
    fun();
    printf("");
    return 0;
}
void fun()
{
    char c;
    if((c = getchar())!= '')
        fun();
    printf("%c", c);
}

abc abc
bca
Infinite loop
cba
Which of the following function is more appropriate for reading in a multi-word string?

printf();
scanf();
gets();
puts();
What will be the output of the program ?
#include<stdio.h>

int main()
{
    printf("Astiwz", "QUIZ");
    return 0;
}

Error
Astiwz QUIZ
Astiwz
QUIZ
Which of the following function is correct that finds the length of a string?

int xstrlen(char *s)
{
    int length=0;
    while(*s!='')
    {    length++; s++; }
    return (length);
}
int xstrlen(char s)
{
    int length=0;
    while(*s!='')
        length++; s++;
    return (length);
}
int xstrlen(char *s)
{
    int length=0;
    while(*s!='')
        length++;
    return (length);
}
int xstrlen(char *s)
{
    int length=0;
    while(*s!='')
        s++;
    return (length);
}
What will be the output of the program ?
#include<stdio.h>

int main()
{
    char str[7] = "ASTIWZ";
    printf("%s", str);
    return 0;
}

Error
ASTIWZ
Cannot predict
None of above
What will be the output of the program ?
#include<stdio.h>

int main()
{
    char *names[] = { "Suresh", "Siva", "Sona", "Baiju", "Ritu"};
    int i;
    char *t;
    t = names[3];
    names[3] = names[4];
    names[4] = t;
    for(i=0; i<=4; i++)
        printf("%s,", names[i]);
    return 0;
}

Suresh, Siva, Sona, Baiju, Ritu
Suresh, Siva, Sona, Ritu, Baiju
Suresh, Siva, Baiju, Sona, Ritu
Suresh, Siva, Ritu, Sona, Baiju
What will be the output of the program ?
#include<stdio.h>
#include<string.h>

int main()
{
    char str[] = "AstiwzQUIZ";
    printf("%d", strlen(str));
    return 0;
}

10
6
5
11
What will be the output of the program ?
#include<stdio.h>
#include<string.h>

int main()
{
    static char str1[] = "dills";
    static char str2[20];
    static char str3[] = "Daffo";
    int i;
    i = strcmp(strcat(str3, strcpy(str2, str1)), "Daffodills");
    printf("%d", i);
    return 0;
}

0
1
2
4
What will be the output of the program ?
#include<stdio.h>
#include<string.h>

int main()
{
    static char s[] = "Hello!";
    printf("%d", *(s+strlen(s)));
    return 0;
}

8
0
16
Error
What will be the output of the program ?
#include<stdio.h>

int main()
{
    static char s[25] = "The cocaine man";
    int i=0;
    char ch;
    ch = s[++i];
    printf("%c", ch);
    ch = s[i++];
    printf("%c", ch);
    ch = i++[s];
    printf("%c", ch);
    ch = ++i[s];
    printf("%c", ch);
    return 0;
}

hhe!
he c
The c
Hhec
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;
}

8, 1, 4
4, 2, 8
4, 2, 4
10, 3, 4
What will be the output of the program ?
#include<stdio.h>

int main()
{
    int i;
    char a[] = "";
    if(printf("%s", a))
        printf("The string is empty");
    else
        printf("The string is not empty");
    return 0;
}

The string is empty
The string is not empty
No output
0
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;
}

1, 2, 4
1, 4, 4
2, 2, 4
2, 4, 8
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", sizeof(a), sizeof(b));
    printf("%d, %d", sizeof(*a), sizeof(*b));
    return 0;
}

10, 2
2, 2
10, 4
1, 2
11, 4
1, 1
12, 2
2, 2
What will be the output of the program ?
#include<stdio.h>

int main()
{
    static char mess[6][30] = {"Don't walk in front of me...", 
                               "I may not follow;", 
                               "Don't walk behind me...", 
                               "Just walk beside me...", 
                               "And be my friend." };

    printf("%c, %c", *(mess[2]+9), *(*(mess+2)+9));
    return 0;
}

t, t
k, k
n, k
m, f
What will be the output of the program ?
#include<stdio.h>

int main()
{
    char str1[] = "Hello";
    char str2[10];
    char *t, *s;
    s = str1;
    t = str2;
    while(*t=*s)
        *t++ = *s++;
    printf("%s", str2);
    return 0;
}

Hello
HelloHello
No output
ello
What will be the output of the program ?
#include<stdio.h>

int main()
{
    char str[] = "AstiwzQUIZ";
    printf("%d", sizeof(str));
    return 0;
}

10
6
5
11
What will be the output of the program ?
#include<stdio.h>

int main()
{
    char str[25] = "ASTIWZ";
    printf("%s", &str+2);
    return 0;
}

Garbage value
Error
No output
diaQUIZ
What will be the output of the program ?
#include<stdio.h>

int main()
{
    char str = "ASTIWZ";
    printf("%s", str);
    return 0;
}

Error
ASTIWZ
Base address of str
No output
What will be the output of the program ?
#include<stdio.h>

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

Kagpur, Kanpur
Nagpur, Kanpur
Kagpur, anpur
Error
What will be the output of the program ?
#include<stdio.h>

int main()
{
    printf(5+"ASTIWZ");
    return 0;
}

Error
ASTIWZ
QUIZ
None of above
What will be the output of the program ?
#include<stdio.h>
#include<string.h>

int main()
{
    char sentence[80];
    int i;
    printf("Enter a line of text");
    gets(sentence);
    for(i=strlen(sentence)-1; i >=0; i--)
        putchar(sentence[i]);
    return 0;
}

The sentence will get printed in same order as it entered
The sentence will get printed in reverse order
Half of the sentence will get printed
None of above
What will be the output of the program ?
#include<stdio.h>
void swap(char *, char *);

int main()
{
    char *pstr[2] = {"Hello", "ASTIWZ"};
    swap(pstr[0], pstr[1]);
    printf("%s%s", pstr[0], pstr[1]);
    return 0;
}
void swap(char *t1, char *t2)
{
    char *t;
    t=t1;
    t1=t2;
    t2=t;
}

ASTIWZ
Hello
Address of "Hello" and "ASTIWZ"
Hello
ASTIWZ
Iello
HndiaQUIZ
What will be the output of the program (Turbo C in 16 bit platform DOS) ?
#include<stdio.h>
#include<string.h>

int main()
{
    char *str1 = "Astiwz";
    char *str2 = "QUIZ";
    char *str3;
    str3 = strcat(str1, str2);
    printf("%s %s", str3, str1);
    return 0;
}

ASTIWZ Astiwz
ASTIWZ ASTIWZ
Astiwz Astiwz
Error
If the size of pointer is 4 bytes then What will be the output of the program ?
#include<stdio.h>

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

22, 4
25, 5
24, 5
20, 2
What will be the output of the program ?
#include<stdio.h>

int main()
{
    int i;
    char a[] = "";
    if(printf("%s", a))
        printf("The string is not empty");
    else
        printf("The string is empty");
    return 0;
}

The string is not empty
The string is empty
No output
0
What will be the output of the program ?
#include<stdio.h>
#include<string.h>

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

Unpredictable integer value
0
-1
Error
What will be the output of the program in Turbo C?
#include<stdio.h>

int main()
{
    char str[10] = "Astiwz";
    str[6] = "QUIZ";
    printf("%s", str);
    return 0;
}

Astiwz QUIZ
QUIZ
Astiwz
Error
What will be the output of the program ?
#include<stdio.h>

int main()
{
    char str1[] = "Hello";
    char str2[] = "Hello";
    if(str1 == str2)
        printf("Equal");
    else
        printf("Unequal");
    return 0;
}

Equal
Unequal
Error
None of above
What will be the output of the program ?
#include<stdio.h>

int main()
{
    char t;
    char *p1 = "Astiwz", *p2;
    p2=p1;
    p1 = "QUIZ";
    printf("%s %s", p1, p2);
    return 0;
}

Astiwz QUIZ
QUIZ Astiwz
Astiwz Astiwz
QUIZ QUIZ
What will be the output of the program ?
#include<stdio.h>
#include<string.h>

int main()
{
    printf("%c", "abcdefgh"[4]);
    return 0;
}

Error
d
e
abcdefgh
What will be the output of the following program in 16 bit platform (in Turbo C under DOS) ?
#include<stdio.h>

int main()
{
    printf("%u %s", &"Hello", &"Hello");
    return 0;
}

177 Hello
Hello 177
Hello Hello
Error