This set of C Multiple Choice Questions & Answers (MCQs) focuses on “Character Pointers and Functions – 1”.
Pre-requisite for C Character Pointers and Functions MCQ set: Video Tutorial on C Pointers.
1. What will be the output of the following C code?
#include <stdio.h>
int main()
{
char *str = "hello, world\n";
char *strc = "good morning\n";
strcpy(strc, str);
printf("%s\n", strc);
return 0;
}
a) hello, world
b) Crash/segmentation fault
c) Undefined behaviour
d) Run time error
View Answer
Explanation: None.
2. What will be the output of the following C code?
#include <stdio.h>
int main()
{
char *str = "hello world";
char strc[] = "good morning india\n";
strcpy(strc, str);
printf("%s\n", strc);
return 0;
}
a) hello world
b) hello worldg india
c) Compile time error
d) Undefined behaviour
View Answer
Explanation: None.
3. What will be the output of the following C code?
#include <stdio.h>
int main()
{
char *str = "hello, world!!\n";
char strc[] = "good morning\n";
strcpy(strc, str);
printf("%s\n", strc);
return 0;
}
a) hello, world!!
b) Compile time error
c) Undefined behaviour
d) Segmenation fault
View Answer
Explanation: None.
4. What will be the output of the following C code?
#include <stdio.h>
int main()
{
char *str = "hello, world\n";
str[5] = '.';
printf("%s\n", str);
return 0;
}
a) hello. world
b) hello, world
c) Compile error
d) Segmentation fault
View Answer
Explanation: None.
5. What will be the output of the following C code?
#include <stdio.h>
int main()
{
char str[] = "hello, world";
str[5] = '.';
printf("%s\n", str);
return 0;
}
a) hello. world
b) hello, world
c) Compile error
d) Segmentation fault
View Answer
Explanation: None.
6. What will be the output of the following C code?
#include <stdio.h>
int main()
{
char *str = "hello world";
char strary[] = "hello world";
printf("%d %d\n", sizeof(str), sizeof(strary));
return 0;
}
a) 11 11
b) 12 12
c) 4 12
d) 4 11
View Answer
Explanation: None.
7. What will be the output of the following C code?
#include <stdio.h>
int main()
{
char *str = "hello world";
char strary[] = "hello world";
printf("%d %d\n", strlen(str), strlen(strary));
return 0;
}
a) 11 11
b) 12 11
c) 11 12
d) x 11 where x can be any positive integer.
View Answer
Explanation: None.
8. What will be the output of the following C code?
#include <stdio.h>
void f(char *k)
{
k++;
k[2] = 'm';
printf("%c\n", *k);
}
void main()
{
char s[] = "hello";
f(s);
}
a) l
b) e
c) h
d) o
View Answer
Explanation: None.
9. What will be the output of the following C code?
#include <stdio.h>
void fun(char *k)
{
printf("%s", k);
}
void main()
{
char s[] = "hello";
fun(s);
}
a) hello
b) Run time error
c) Nothing
d) h
View Answer
Explanation: None.
Sanfoundry Global Education & Learning Series – C Programming Language.
To practice all areas of C language, here is complete set of 1000+ Multiple Choice Questions and Answers.
- Check Computer Science Books
- Watch Advanced C Programming Videos
- Check C Books
- Practice BCA MCQs
- Practice Computer Science MCQs