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 *str=”Hello world”;
printf(“%d”,printf(“%s”,str));
}

  1. 12Hello world
  2. 11Hello world
  3. Hello world12
  4. Hello world11

Answer :

Ans : 4, First it prints the string and returns the length 11

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

  1. Compile time error
  2. Java2Pyt
  3. Java2Py
  4. Java2Python

Answer :

Ans : 1, We cannot assign a string value which is out of length

What is the Output of following Code?
#include<stdio.h>
int main()
{
char* s[5] = {“one”, “two”, “three”, “four”,”five”};
int i=0,j=4;
char* t;
while(++i < j–)
{
t = s[i];
s[i] = s[j];
s[j] = t;
}
printf(“%s”,*(s + ++i));
return 0;
}

  1. three
  2. four
  3. five
  4. two

Answer :

Ans : 3

What is the Output of following Code?
#include<stdio.h>
int main()
{
char s1[10] = “hello”;
char s2[10] = “world”;
strncat(s1, s2, 2);
printf(“%s”, s1+1);
return 0;
}

  1. wo
  2. elloworld
  3. o
  4. ellowo

Answer :

Ans : 4

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

  1. Compile time error
  2. LLO
  3. LO
  4. ELLO

Answer :

Ans : 2

What is the Output of following Code?
#include<stdio.h>
int main()
{
printf(“\”JP%Java2Python%!\””);
return 0;
}

  1. \JP%Java2Python%!\
  2. “\”JP%Java2Python%!”\”
  3. “JP%Java2Python%!”
  4. Compile time error

Answer :

Ans : 3

What is the Output of following Code?
#include<stdio.h>
void main()
{
float f =65.56 ;
printf(“%c \n”, (int)f);
}

  1. blank character
  2. 6
  3. Garbage character
  4. A

Answer :

Ans : 4

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

  1. o, E, n
  2. o, E, i
  3. d, E, n
  4. d, E, i

Answer :

Ans : 2

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

  1. Java2Python, J, J
  2. Java2Python, Garbage character, J
  3. Java2Python, J, Garbage character
  4. Compile time error

Answer :

Ans : 2

What is the Output of following Code?
#include<stdio.h>
int main()
{
char str[20] = “Java2Python”;
char *p, *q, *r;
p=str;
q=p++;
r=p+3 – (q-p);
printf(“%3s %5s”, (++p)+3, r);
return 0;
}

  1. Python Python
  2. Compile time error
  3. Python 2Python
  4. 2Python 2Python

Answer :

Ans : 1

Strings – Technical – Part 3

Share this