What is the difference between string and array

Interview Questions
  • What is the difference between string and array.
  • What is the difference between strcpy() and strncpy() String functions in C.
  • What is the difference between memcpy() and memmove() String functions in C.

What is the difference between string and array in C

  • Arrays in C can store any data type whereas Strings can store only char data.
  • A C String must be terminated by a null character('\0') whereas there is no such restrictions in Array.
  • An array can be of any length, unless we don't specify the length of array there is no way to determine the end of array whereas a String is terminated by a null character('\0') which represents the end of string.


What is the difference between strcpy() and strncpy() String functions in C

The function char strcpy(char *destination, const char *source); copies the string pointed by source into the string pointed by destination including the null character('\0').
The function char *strncpy(char *destination, const char *source, size_t n); copies the first n characters from the string pointed by source to string pointed by destination. If the length of source string is less than n, then destination string is padded with zeros until a total of n characters have been written into it.

Related Links :
strncpy() function in C
strcpy() function in C


What is the difference between memcpy() and memmove() String functions in C

The function void *memcpy(void *destination, const void *source, size_t n); copies first n bytes from memory location pointed by source to memory location pointed by destination. It does the binary copy of the data. It always copies exactly num bytes without checking for terminating null character('\0') in source.

The function void *memmove ( void *destination, const void *source, size_t n); copies first n bytes from memory location pointed by source to memory location pointed by destination. It does the binary copy of the data. We can copy overlapping source and destination memory locations using memmove function.
The main difference between memcpy and memmove is the memory handling when source and destination overlaps.

Related Links :
memcpy() function in C
memmove() function in C


Related Topics
What is the difference between pre (++var) and post(var++) increment operator.
What is the difference between & and * operators in C
What is the difference between = and == operators in C
What is Array in C programming language.
What are advantages and disadvantages of Arrays in C.
What is Wild pointer in C.
What is difference between uninitialized(wild) pointer and null pointer
What is the scope of local and global variables in C.
What is difference between Call by value and Call by reference in C.
What is Address Of(&) Operator and Value Of(*) Operator in C.