Skip to content

Tag Archives: C Array and String

Consider below two statements in C. What is the difference between the two?  char s[] = "geeksquiz"; char *s = "geeksquiz"; Below are the key… Read More
Variable length arrays are also known as runtime sized or variable sized arrays. The size of such arrays is defined at run-time.  Variably modified types… Read More
In C, it is possible to have array of all types except following. 1) void. 2) functions. For example, below program throws compiler error int… Read More
Image a situation where we want to use or print a long long string in C or C++, how to do this? In C/C++, we… Read More
This post is an extension of How to dynamically allocate a 2D array in C? A one dimensional array can be easily passed as a pointer,… Read More
  Following are different ways to create a 2D array on the heap (or dynamically allocate a 2D array).In the following examples, we have considered… Read More
  Pointers are used for storing address of dynamically allocated arrays and for arrays which are passed as arguments to functions. In other contexts, arrays… Read More
The C99 standard allows variable sized arrays (see this). But, unlike the normal arrays, variable sized arrays cannot be initialized. For example, the following program… Read More
In C/C++, we can assign a struct (or class in C++ only) variable to another variable of same type. When we assign a struct variable… Read More
In C/C++, when a character array is initialized with a double quoted string and array size is not specified, compiler automatically allocates one extra space… Read More
In C/C++, initialization of a multidimensional arrays can have left most dimension as optional. Except the left most dimension, all other dimensions must be specified. For… Read More
Recursion can be used to do both tasks in one line. Below are one line implementations for stracat() and strcmp(). /* my_strcat(dest, src) copies data… Read More
Using sizeof directly to find the size of arrays can result in an error in the code, as array parameters are treated as pointers. Consider… Read More
Consider the below program.  C void read() {    char str[20];    gets(str);    printf("%s", str);    return; } The code looks simple, it reads string from standard input… Read More
Let us consider the below program.   C #include<stdio.h> void swap(char *str1, char *str2) { char *temp = str1; str1 = str2; str2 = temp;… Read More