C Technical Interview Questions on Strings

These C Technical Interview Questions on Strings post providing basic, intermediate and Hard level examples in C Strings. The Practice of these examples makes you good in C programming.


What is the Output of following Code?
#include<stdio.h>
void main()
{
char s1[ ]=”Java2Python”, s2[ ]=”.com”;
printf(“%s”,s1+strlen(s2));
}

  1. 2Python
  2. 2Python.com
  3. Java2Python2Python
  4. 2Python2Python

Answer :

Ans : 1

What is the Output of following Code?
#include<stdio.h>
int main()
{
char *p=”abc” , *q=”123″;
int x=1 ;
while(*p=*q && ++x<=5)
{
printf(“%c%d\n”,*q,x);
}
return 0;
}

  1. a2, b3, c4
  2. 12, a3, b4
  3. 12, 13, 14, 15
  4. Compile time error

Answer :

Ans : 3

What is the Output of following Code?
#include<stdio.h>
void main()
{
char s[ ]=”\0Clang”;
if(printf(“%s”,s))
printf(“TRUE”);
else
printf(“FALSE”);
}

  1. ClangTRUE
  2. TRUE
  3. ClangFALSE
  4. FALSE

Answer :

Ans : 4

What is the Output of following Code?
#include<stdio.h>
int main()
{
if(strlen(“Hai”) == printf(“Hi.”))
printf(“…Programmers”);
else
printf(“…Developers”);
return 0;
}

  1. Hi…Programmers
  2. Hi…Developers
  3. Programmers
  4. Developers

Answer :

Ans : 1

 

What is the Output of following Code?
#include<stdio.h>
int main()
{
char str[7] = “CBooks”;
int i=0 ;
while(str[++i])
printf(“%c\n”,str[i+1]);
return 0;
}

  1. CBooks
  2. oks
  3. Books
  4. ooks

Answer :

Ans : 4

What is the Output of following Code?
#include<stdio.h>
void main()
{
char* str = “learnown”;
printf(“%c\n” , *(str++ + 2)+3);
printf(“%c\n” , *++str+2);
printf(“%s\n” , –str-1);
}

  1. d, c, learnown
  2. r, c, learnown
  3. r, r, learnown
  4. d, r, learnown

Answer :

Ans : 1

What is the Output of following Code?
#include<stdio.h>
void main()
{
char *s[ ] = {“black”, “white”, “pink”, “violet”};
char **ptr[ ] = {s+3, s+2, s+1, s};
char ***p;
p = ptr;
++p;
printf(“%s\n”, (*(*p+1)+1)+2);
}

  1. white
  2. ink
  3. let
  4. ack

Answer :

Ans : 3

 

Strings – Objective – Part 1

Share this