github

Made bySaurav Hathi

MCQ Test C/C++: Strings and Date

Q1:

What is the output of this C++ program?

#include <iostream>

#include <cstring>

using namespace std;

int main ()

{

char str1[10] = "Hello";

char str2[10] = "World";

char str3[10];

int  len ;

strcpy( str3, str1);

strcat( str1, str2);

len = strlen(str1);

cout << len << endl;

return 0;

}

Tags:
Section:
Core Programming
Options:
Q2:

What is the output of this C++ program?

#include <iostream>

#include <string>

using namespace std;

int main ()

{

string str ("microsoft");

string::reverse_iterator r;

for (r = str.rbegin() ; r < str.rend(); r++ )

cout << *r;

return 0;

}

Tags:
Section:
Core Programming
Options:
Q3:

What is the output of this C++ program?

#include <iostream>

#include <string>

using namespace std;

int main ()

{

string str ("nobody does like this");

string key ("nobody");

size_t f;

f = str.rfind(key);

if (f != string::npos)

str.replace (f, key.length(), "everybody");

cout << str << endl;

return 0;

}

Tags:
Section:
Core Programming
Options:
Q4:

What is the output of this C++ program?

#include <iostream>

#include <string>

using namespace std;

int main ()

{

string str ("steve jobs is legend");

string::iterator it;

str.erase (str.begin()+ 5, str.end()-7);

cout << str << endl;     

return 0;

}

Tags:
Section:
Core Programming
Options:
Q5:

What is the output of this C++ program?

#include <iostream>

#include <string>

using namespace std;

int main ()

{

string str ("Microsoft");

for (size_t i = 0; i < str.length();)

{

cout << str.at(i-1);

}

return 0;

}

Tags:
Section:
Core Programming
Options:
Q6:

What is the output of this C++ program?

#include <iostream>

#include <string>

using namespace std;

int main ()

{

string str ("Ubuntu");

cout << str.capacity();

cout << str.max_size();

return 0;

}

Tags:
Section:
Core Programming
Options:
Q7:

How many types of representation are in string in C++?

Tags:
Section:
Core Programming
Options:
Q8:

Which function is used to return the number of characters in a string in C++?

Tags:
Section:
Core Programming
Options:
Q9:

What is the output of this C++ program?

#include <iostream>

using namespace std;

int main()

{

char str[5] = "ABC";

cout << str[3];

cout << str;

return 0;

}

Tags:
Section:
Core Programming
Options:
Q10:

What will be the output of the following C program?

#include<stdio.h>

int main()

{

char str1[ ] = "abcd";

char str2[ ] = "abcd";

if(str1==str2)

printf("Equal");

else

printf("Unequal");

}

Tags:
Section:
Core Programming
Options:
Q11:

If the two strings are equal, then the C function strcmp() returns the value?

Tags:
Section:
Core Programming
Options:
Q12:

In C/C++ which inbuilt function is used to find the last occurrence of a character in a given string?

Tags:
Section:
Core Programming
Options:
Q13:

What will be the output of this C program ?

#include<stdio.h>

#include<string.h>

int main()

{

char str1[20] = "Hello", str2[20] = "World";

printf("%s", strcpy(str2, strcat(str1, str2)));

}

Tags:
Section:
Core Programming
Options:
Q14:

What will be the output of this C program ?

#include<stdio.h>

int main()

{

printf(5+"Good Morning\n");

}

Tags:
Section:
Core Programming
Options:
Q15:

What will be the output of this C program ?

#include<stdio.h>

int main()

{

char str[ ] = "Hello\0World";

printf("%s", str);

}

Tags:
Section:
Core Programming
Options:
Q16:

What is the output of this C code?

#include <stdio.h>

int main()

{

char *s= "hello";

char *p = s;

printf("%c %c", 1[p], s[1]);

}

Tags:
Section:
Core Programming
Options:
Q17:

What is the output of this C code?

#include <stdio.h>

int main()

{

char *s = "hello";

char *n = "cjn";

char *p = s + n;

printf("%c %c", *p, s[1]);

}

Tags:
Section:
Core Programming
Options:
Q18:

What is the output of this C code?

#include <stdio.h>

#include<string.h>

int main()

{

char *str = "hello, world\n";

char *strc = "good morning\n";

strcpy(strc, str);

printf("%s\n", strc);

return 0;

}

Tags:
Section:
Core Programming
Options:
Q19:

What is the output of this C code if an integer pointer value takes 4 bytes and a character takes 1 byte?

#include <stdio.h>

int main()

{

char *str = "hello world";

char strary[ ] = "hello world";

printf("%d %d\n", sizeof(str), sizeof(strary));

return 0;

}

Tags:
Section:
Core Programming
Options:
Q20:

What is the output of this C code?

#include <stdio.h>

void fun(char *k)

{

k++;

k[2] = 'm';

printf("%c\n", *k);

}

int main()

{

char s[ ] = "hello";

fun(s);

}

Tags:
Section:
Core Programming
Options: