Question

What is the difference between the following two declarations? char array[] = “Hello World”; char *array...

What is the difference between the following two declarations?

char array[] = “Hello World”;

char *array = “Hello World”;

Homework Answers

Answer #1

The answer to this question is as follows:

The basic difference between the char array[] and char* array is one is pointer variable and other one is the array that it holds the values

The char *array is a variable that we can initialize with the values but the char array[] is of array type we can perform indexing on this and the value starts from the address that holds the 'H'

and also one major difference is running time complexity

For example:

char *array="world" if you want to print from "orld" then you can shift the pointer to the right by using array++

it takes O(1) time complexity

but with the char array[] takes O(n) time complexity because it needs to run through out the loop so it takes for loop  and taking the index values from the 1 to n so it takes the time complexity of O(n)

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
The funciton my_strcpy(char dest, const char cource) is to copy "hello world" from source to dest....
The funciton my_strcpy(char dest, const char cource) is to copy "hello world" from source to dest. Do not use the library. The copy process will only stop at the last "\0". Make sure dest is large enough to any lenght of sentence inputted. The following is my code. The program copy the first letter of "hello world" which is "h", but the requirement is to copy the whole sentence "hello world". Thank you for your helps #include <iostream> using namespace...
What is wrong with the following code segment, assumming it compiles correctly? char *a = "Hello";...
What is wrong with the following code segment, assumming it compiles correctly? char *a = "Hello"; char *b = " Mom"; while( *b != '\0' ) { *a = *b; a++; b++; }
1) Explain the difference between: Array of characters like char c[] = {'A', 'B', 'C'}; AND...
1) Explain the difference between: Array of characters like char c[] = {'A', 'B', 'C'}; AND c-string like string = "ABC"; 2) We can have two pointers that point to one memory location such as: int *intPtr1, *intPtr2; intPtr1 = &x; intPtr2 = &x; a) What method we have to make sure only one pointer points to a variable? b) Give an example. 3) a) Can a pointer to a constant receive an address of a constant item and/or non-constant...
List the errors in the following array declarations. A. int intArray[] = new double[10]; B. int...
List the errors in the following array declarations. A. int intArray[] = new double[10]; B. int intArray[] = new int[1.5]; C. double[] doubleArray = new double[-10] D. int intMatrix[] [] = new int[10]; - Write a method selectRandom that expects an array of integers as a parameter. The method should return the value of an array element at a randomly selected position.
In the context of MISO and SIMO systems, what is the difference between array gain and...
In the context of MISO and SIMO systems, what is the difference between array gain and diversity gain?
What's the difference between the natural world and the social world, according to Alfred Schutz?
What's the difference between the natural world and the social world, according to Alfred Schutz?
Programming in C: 1. Given the following variable declarations: const size_t n = 50; 2. Write...
Programming in C: 1. Given the following variable declarations: const size_t n = 50; 2. Write the declaration of an an array of pointers to n memory blocks containing 16-bit signed integer values. Use 'x' for the name of the variable. 3. What is the type of the variable x? uint8_t *x[256]; 4. What type does the variable x decay to when used in an expression? uint8_t *x[256] 5. What is the data type of an array of five strings?...
What is the difference between: Gross investment and net investment? Provide a real world example of...
What is the difference between: Gross investment and net investment? Provide a real world example of each one. (10)
Explain double ended queue as an array ? and what are the real world example of...
Explain double ended queue as an array ? and what are the real world example of double ended queue. Explain?
What is the difference between: Final goods and intermediate goods? Then Provide a real world example...
What is the difference between: Final goods and intermediate goods? Then Provide a real world example of each one.(10) and what is the diffrence between GDP and GNP. Explain in detail. (15) in your own words