Select chapter



functions (3.papers)
loops (1.papers)
arrays (2.papers)
structures (3.papers)
unions (1.papers)
pointers (7.papers)
null pointers (1.papers)
strings (2.papers)
misc c concepts (1.papers)
Data structures (5.papers)
linked lists (3.papers)
trees (1.papers)
basics (5.papers)
Hide

Sponsored Links


  

c strings interview questions and answers

Show Answer
Share Facebook gmail Twitter
2
Sample code for using strcat() method in c:

What is the output of below c program?

#include  <stdio.h>

int main(void)
{
    char ch[] = "technologies";
    char des[25] = "skill gun ";
    strcat(des, ch);
    
    printf("%s",des);
    return 0;
}
  1. compile time error, insufficient memory.
  2. run time error "in sufficient memory" or garbage value or may be crash.
  3. skill gun technologies
  4. technologiesskill gun .
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
14
Demo code for function returning pointer in c:

What is the output of below program

char *myfunc()
{
    char *temp = "string";
    return temp;
}
int main()
{
    puts(someFun());
}
  1. it crashes at run time.
  2. output will be "string".
  3. it won't print any thing. but no error and no crash.
  4. it prints "s".
Show Answer
Share Facebook gmail Twitter
15
What is the below program doing?
why does it have second parameter as const?

void strfun(char dst[], const char src[])
{
    int i = 0;
    while (src[i] != '\0')
    {
      dst[i] = src[i];
      i++;
    }
    dst[i] = '\0';
}
  1. This program is copying source content to destination completely. after copying it is appending null termination to second string. second parameter is constant, because generally when we pass our string data to some one to copy, they should not manipulate our string, so in order to avoid it, we have passed as constant.
  2. This program is copying source content to destination completely. after copying it is appending null termination to second string. second parameter is constant, because generally when we pass our string to some one to copy, they should not manipulate the address of our source string, so in order to avoid it, we have passed as constant.
  3. This program is copying source content to destination completely. after copying it is removing all characters and replacing with null value to second string. second parameter is constant, because generally when we pass our string data to some one to copy, they should not manipulate our string, so in order to avoid it, we have passed as constant.
  4. This program is copying source content to destination completely. after copying it is removing all characters and replacing with null value to second string.second parameter is constant, because generally when we pass our string to some one to copy, they should not manipulate the address of our source string, so in order to avoid it, we have passed as constant.
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
17
What is the difference between strdup and strcpy in c?
  1. strdup - will create memory for us, creates a duplicate copy of supplied string, returns null if it couldn't duplicate it.
  2. strcpy - we have to allocate memory for destination, and supply both source and destination as parameters, it will simply copy, won't allocate memory. returns null if destination doesn't have enough space to copy.
  3. both option 1 and 2 are reversed.
  4. both option 1 and 2 are correct.
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
20
What is the output of below c program? what is it doing?

int main()
{

  char str2[20],str1[25]="Skill gun technologies";
  int from=10,cnt=4;
  int i;

  printf("main string is..%s\n",str1);

  if(sizeof(str2) < cnt)
   return;

  for(i=0;i<cnt; i++) {
   str2[i]=str1[from+i];
  } 
  str2[i] = '\0';

  printf("\n result string is.. %s",str2);

}
  1. it is a string copy program. it prints skill gun technologies.
  2. it is a substring copy program, it prints "echn".
  3. This program will copy the content from str1 into str2. but it will copy only 'cnt' from 'from'. Output of this program will be " tec".
  4. This program will copy the content from str1 into str2. but it will copy only 'cnt' from 'from'. Output of this program will be "tech".
Show Answer
Share Facebook gmail Twitter
Read more papers :