C Technical Interview Questions on Strings

This 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 s[ ] = “HamaM”;
s[2]<s[strlen(s)-1] ? printf(“Yes”) : printf(“No”);
}

  1. Yes
  2. No
  3. Compile time error
  4. 0Yes

Answer :

Ans : 2

What is the Output of following Code?
#include<stdio.h>
void main()
{
int i;
char s[ ]=”Clanguage”;
for(i=0 ; s[i]!=’\0′ ; i++)
{
putchar(s[i]);
putchar(‘*’);
}
}

  1. Clanguage*
  2. C*l*a*n*g*u*a*g*e*
  3. *Clanguage
  4. Clanguag*

Answer :

Ans : 2

What is the Output of following Code?
#include<stdio.h>
int main()
{
char *p=”CBOOK”;
printf (“%c\t”, *(++p));
p -=1;
printf (“%c\t”, *(p++));
return 0;
}

  1. B, C
  2. C, B
  3. B, B
  4. C, C

Answer :

Ans : 1

What is the Output of following Code?
#include<stdio.h>
void main()
{
char s[10] = “CQuestions”;
printf(“%c”, 3[s]);
}

  1. Garbage character
  2. Compile time error
  3. e
  4. Runtime error : No such location

Answer :

Ans : 3

What is the Output of following Code?
#include<stdio.h>
void main()
{
int x ;
if(x=printf(“Hello\n”))
{
printf(“x : %d”,x);
}
}

  1. Hello, x=6
  2. Hello, x=5
  3. Hello, x=7
  4. Compile time error

Click here to learn more

Ans : 1

What is the Output of following Code?
#include<stdio.h>
int main()
{
int i=0;
char ch = ‘B’;
do
putchar (ch);
while(i++ < 2 || ++ch <= ‘D’);
printf(“%c “,ch);
return 0;
}

  1. BCDE
  2. BBCDD
  3. BBBCDE
  4. BBCDE

Answer :

Ans : 3

What is the Output of following Code?
#include<stdio.h>
void main()
{
char s[2];
s[0]=’H’ , s[1]=’a’ , s[2]=’i’ ;
printf(“%s”,s);
}

  1. Ha
  2. Hai
  3. Hai and garbage characters
  4. Compile time error

Answer :

Ans : 3

What is the Output of following Code?
#include<stdio.h>
int main()
{
char *p = “Oracle India”;
p[5] == ‘l’ ? printf(“Orcle”) : printf(“India”);
return 0;
}

  1. India
  2. Oracle
  3. Compile time error
  4. None of the above

Answer :

Ans : 1

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

  1. n, n
  2. n, nown
  3. o, nown
  4. o, n

Answer :

Ans : 3

 

Strings – Technical – Part 4

Share this