Question 11
#include <stdio.h>
int fun(char *p)
{
if (p == NULL || *p == \'\\0\') return 0;
int current = 1, i = 1;
while (*(p+current))
{
if (p[current] != p[current-1])
{
p[i] = p[current];
i++;
}
current++;
}
*(p+i)=\'\\0\';
return i;
}
int main()
{
char str[] = \"geeksskeeg\";
fun(str);
puts(str);
return 0;
}
Question 12
int main() {
char p[]="geeksquiz";
char t;
int i,j;
for(i=0,j=strlen(p);i!=j;i++,j--)
{
t=p[i];
p[i]=p[j-i];
p[j-i]=t;
}
printf("%s",p);
return 0;
}
Output?
Question 13
Output of following C program? Assume that all necessary header files are included
int main()
{
char *s1 = (char *)malloc(50);
char *s2 = (char *)malloc(50);
strcpy(s1, \"Geeks\");
strcpy(s2, \"Quiz\");
strcat(s1, s2);
printf(\"%s\", s1);
return 0;
}
Question 14
#include <stdio.h>
char str1[100];
char *fun(char str[])
{
static int i = 0;
if (*str)
{
fun(str+1);
str1[i] = *str;
i++;
}
return str1;
}
int main()
{
char str[] = \"GATE CS 2015 Mock Test\";
printf(\"%s\", fun(str));
return 0;
}
Question 15
void foo (char *a)
{
if (*a && *a != ` `)
{
foo(a+1);
putchar(*a);
}
}
Question 16
#include <stdio.h>
struct Ournode {
char x, y, z;
};
int main() {
struct Ournode p = {\'1\', \'0\', \'a\' + 2};
struct Ournode *q = &p;
printf(\"%c, %c\", *((char *)q + 1), *((char *)q + 2));
return 0;
}
Question 17
Assume that a character takes 1 byte. Output of following program?
#include<stdio.h>
int main()
{
char str[20] = \"GeeksQuiz\";
printf (\"%d\", sizeof(str));
return 0;
}
Question 18
Predict the output of following program, assume that a character takes 1 byte and pointer takes 4 bytes.
#include <stdio.h>
int main()
{
char *str1 = \"GeeksQuiz\";
char str2[] = \"GeeksQuiz\";
printf(\"sizeof(str1) = %d, sizeof(str2) = %d\",
sizeof(str1), sizeof(str2));
return 0;
}
Question 19
A language with string manipulation facilities uses the following operations.
head(s)- returns the first character of the string s
tail(s)- returns all but the first character of the string s
concat(sl, s2)- concatenates string s1 with s2.
The output of concat(head(s), head(tail(tail(s)))), where s is acbc is
Question 20
In below program, what would you put in place of “?” to print “Quiz”?
#include <stdio.h>
int main()
{
char arr[] = \"GeeksQuiz\";
printf(\"%s\", ?);
return 0;
}
There are 21 questions to complete.