Tutorials
Search... Sign In
Practice
Jobs
DSA Practice Problems C C++ Java Python JavaScript Data Science Machine Learning Courses Linux DevOps SQL Web Develop
C String
Last Updated : Mar 19, 2024 Discuss
Question 1
Consider the following code. The function myStrcat concatenates two strings. It appends all characters of b to end of a. So the expected
output is "Geeks Quiz". The program compiles fine but produces segmentation fault when run.
#include <stdio.h>
void myStrcat(char *a, char *b)
{
int m = strlen(a);
int n = strlen(b);
int i;
for (i = 0; i <= n; i++)
a[m+i] = b[i];
}
int main()
{
char *str1 = "Geeks ";
char *str2 = "Quiz";
myStrcat(str1, str2);
printf("%s ", str1);
printf("%s ", str1);
return 0;
}
Which of the following changes can correct the program so that it prints "Geeks Quiz"?
A char *str1 = "Geeks "; can be changed to char str1[100] = "Geeks ";
B char *str1 = "Geeks "; can be changed to char str1[100] = "Geeks "; and a line a[m+n-1] = \'\\0\' is added at the end of myStrcat
C A line a[m+n-1] = \'\\0\' is added at the end of myStrcat
D A line \'a = (char *)malloc(sizeof(char)*(strlen(a) + strlen(b) + 1)) is added at the beginning of myStrcat()
Discuss it
Question 2
What is the output of following program ?
# include <stdio.h>
int main()
{
char str1[] = "GeeksQuiz";
char str2[] = {'G', 'e', 'e', 'k', 's', 'Q', 'u', 'i', 'z'};
int n1 = sizeof(str1)/sizeof(str1[0]);
int n2 = sizeof(str2)/sizeof(str2[0]);
printf("n1 = %d, n2 = %d", n1, n2);
return 0;
}
We use cookies to ensure you have the best browsing experience on our website. By using our site, you
Got It !
acknowledge that you have read and understood our Cookie Policy & Privacy Policy
A n1 = 10, n2 = 9
B n1 = 10, n2 = 10
C n1 = 9, n2 = 9
D n1 = 9, n2 = 10
Discuss it
Question 3
What is the output of following program?
#include<stdio.h>
void swap(char *str1, char *str2)
{
char *temp = str1;
str1 = str2;
str2 = temp;
}
int main()
{
char *str1 = "Geeks";
char *str2 = "Quiz";
swap(str1, str2);
printf("str1 is %s, str2 is %s", str1, str2);
return 0;
}
A str1 is Quiz, str2 is Geeks
B str1 is Geeks, str2 is Quiz
C str1 is Geeks, str2 is Geeks
D str1 is Quiz, str2 is Quiz
Discuss it
Question 4
Predict the output?
#include <stdio.h>
int fun(char *str1)
{
char *str2 = str1;
while(*++str1);
return (str1-str2);
}
int main()
{
char *str = "GeeksQuiz";
printf("%d", fun(str));
return 0;
}
We use cookies to ensure you have the best browsing experience on our website. By using our site, you
A 10acknowledge that you have read and understood our Cookie Policy & Privacy Policy
B 9
C 8
D Random Number
Discuss it
Question 5
What does the following fragment of C-program print?
char c[] = "GATE2011";
char *p =c;
printf("%s", p + p[3] - p[1]) ;
A GATE2011
B E2011
C 2011
D 011
Discuss it
Question 6
#include<stdio.h>
int main()
{
char str[] = "GeeksQuiz";
printf("%s %s %s ", &str[5], &5[str], str+5);
printf("%c %c %c ", *(str+6), str[6], 6[str]);
return 0;
}
A Runtime Error
B Compiler Error
C uiz uiz uiz u u u
D Quiz Quiz Quiz u u u
Discuss it
Question 7
Output?
We use cookies to ensure you have the best browsing experience on our website. By using our site, you
acknowledge that you have read and understood our Cookie Policy & Privacy Policy
int main()
{
char a[2][3][3] = {'g','e','e','k','s','q','u','i','z'};
printf("%s ", **a);
return 0;
}
A Compiler Error
B geeksquiz followed by garbage characters
C geeksquiz
D Runtime Error
Discuss it
Question 8
Consider the following C program segment:
char p[20];
char *s = "string";
int length = strlen(s);
int i;
for (i = 0; i < length; i++)
p[i] = s[length — i];
printf("%s", p);
The output of the program is? (GATE CS 2004)
A gnirts
B gnirt
C string
D no output is printed
Discuss it
Question 9
The Output of the following C code will be?
#include <stdio.h>
void my_toUpper(char* str, int index)
{
*(str + index) &= ~32;
}
int main()
{
char* arr = "geeksquiz";
my_toUpper(arr, 0);
my_toUpper(arr, 5);
printf("%s", arr);
return 0;
}
A useGeeksQuiz
We cookies to ensure you have the best browsing experience on our website. By using our site, you
acknowledge that you have read and understood our Cookie Policy & Privacy Policy
B
B
geeksquiz
C Compiler dependent
D Runtime Error
Discuss it
Question 10
Predict the output of the following program:
#include <stdio.h>
int main()
{
char str[] = "%d %c", arr[] = "GeeksQuiz";
printf(str, 0[arr], 2[arr + 3]);
return 0;
}
A GQ
B 71 81
C 71 Q
D Compile-time error
Discuss it
Tags: C Quiz
There are 21 questions to complete.
Take a part in the ongoing discussion View All Discussion
We use cookies to ensure you have the best browsing experience on our website. By using our site, you
acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Company Explore Tutorials DSA Data Science & Web
About Us Job-A-Thon Python Data Structures ML Technologies
Corporate & Communications Legal Offline Java Algorithms Data Science With HTML
Address: Privacy Policy Classroom C++ DSA for Python CSS
Careers Program PHP Beginners
A-143, 7th Floor, Machine Learning JavaScript
Sovereign Corporate In Media DSA in GoLang Basic DSA ML Maths TypeScript
Tower, Sector- 136, Noida, Contact Us JAVA/C++ SQL Problems Data Visualisation ReactJS
Uttar Pradesh (201305) Corporate Master R Language DSA Roadmap Pandas NextJS
Solution System Android DSA Interview
Registered Address: NumPy NodeJs
Campus Design Questions
K 061, Tower K, Gulshan NLP Bootstrap
Training Master CP Competitive
Vivante Apartment, Sector Deep Learning Tailwind CSS
137, Noida, Gautam Buddh Program Videos Programming
Nagar, Uttar Pradesh,
201305 Python Computer DevOps System School Databases
Tutorial Science Git Design Subjects SQL
Python GATE CS AWS High Level Mathematics MYSQL
Examples Notes Docker Design Physics PostgreSQL
Django Operating Kubernetes Low Level Chemistry PL/SQL
Tutorial Systems Azure Design Biology MongoDB
Python Computer GCP UML Diagrams Social Science
Projects Network DevOps Interview Guide English Grammar
Advertise with us Python Database Roadmap Design Patterns
Tkinter Management OOAD
Web Scraping System System Design
OpenCV Software Bootcamp
Tutorial Engineering Interview
Python Digital Logic Questions
Interview Design
Question Engineering
Maths
Preparation More Courses Programming Clouds/Devops GATE 2026
IBM Languages DevOps GATE CS Rank
Corner Tutorials
Certification C Programming Engineering Booster
Company- Software
Courses with Data AWS Solutions GATE DA Rank
Wise Development
DSA and Structures Architect Booster
Recruitment Software
Placements C++ Certification GATE CS & IT
Process Testing
Web Programming Salesforce Course - 2026
Aptitude Product
Development Course Certified GATE DA
Preparation Management
Data Science Java Administrator Course 2026
Puzzles Project
Programming Programming Course GATE Rank
Company- Management
Languages Course Predictor
Wise Linux
DevOps & Python Full
Preparation Excel
Cloud Course
All Cheat
Sheets
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you
acknowledge that you have read and understood our Cookie Policy & Privacy Policy