answersLogoWhite

0

An array name is a pointer, so using arrays as pointers in function calls is implicit. An example is...

char a[] = "This is the source";

char b[sizeof(a)];

strcpy (b, a);

This is exactly the same1 as saying...

char a[] = "This is the source";

char b[sizeof(a)];

strcpy (&b[0], &a[0]);

... or ...

char* ap = "This is the source";

char* bp = malloc(strlen (ap)+1);

if (bp == NULL) { ... handle memory exception ... }

strcpy (bp, ap);

---------------------------------------------------------------------------------------------

1However, while a and ap have the same value in these examples, they are not really the same. You can assign a new value to ap, but not to a, because a is an r-value that is not allocated a place in memory, as opposed to ap, which is a l-value. To reinforce this, both *ap and a[0] are l-values, meaning the same thing, but not quite so for ap and a. Be careful - they both have the same value, but ap is an assignable l-value, while a is a un-assignable r-value.

User Avatar

Wiki User

14y ago

What else can I help you with?

Related Questions

How to write a C program to find largest 2 numbers using pointers?

program to find maximum of two numbers using pointers


Write a Program to convert decimal number into hexadecimal no without using function and string?

This is not a question.


How to perform string operations like concatenation compare etc without using built in functions?

performing string operation using pointers


Piglatin string in c without using pointer?

Sure, you can write a function in C to convert a string to Pig Latin without using pointers by passing the string as a parameter and manipulating it directly within the function. You can split the string into words, check if a word starts with a vowel or consonant, and then apply the appropriate transformation following the rules of Pig Latin. Remember to allocate enough memory for the modified string to prevent buffer overflow.


How do you write a program using function that counts the number of vowels in a string in java language?

Use text-editor notepad++


Write a program to concate the string without using strconcat function?

If you don't need to preserve the first string you could just iterate over the second string and copy each character onto the end of the first string, then return that


Reverse of a string without using string handling function?

shashi


What will be the program to arrange numbers stored in array in ascending order using pointers?

sorry


Write a c program to copy two strings using pointers?

nahi malum


When do you use pointers in C?

There are many uses of pointer in C. Pointers are efficient and elegant to use. All string variables are pointers, and calling a function using a pointer allows the function to change the value globally. These are what you can do with pointers in C. 1) Returning multiple values by passing address of variables. eg. foo(&a,&b,&c); 2) When you want to modify the value passed to function. eg. scanf() function. int n; scanf("%d",&n); /* pass address of variable n so that scanf can change its value*/ 3) When you need to pass large data structure to function, it is more efficient to pass pointer to structure than passing the entire structure. If you don't want to modify the structure members, you can use 'const' keyword which the ANSI-complaint C compiler will either warn or give error if you modify. eg strlen(const char *str) in string library should not modify the content of str. 4) Implementing 'goto' data structures are easy with pointers. eg. linked-list,binary trees, hash table. 5) You can allocate dynamic memory using pointers. 6) Pointers to function are used for call back function and jump table. eg qsort() and bsearch() functions require the caller to provide pointer to function to do the comparison.


How do you reverse a string in PHP without using a function?

Without any function is impossible. So I'll assume you mean any coded function, in which case the predefined function below is your answer.$string = strrev($string);


Is it possibly to return an array of strings in a function without using pointers in C plus plus?

No.


How do you accept a string by using getch() function with an example?

explain about function call


Concat a string without using any inbuilt function in java?

Use "+". Example: String string = "does this answer " + "your question?";


Write a program in java to display a string message using Servlets?

i dont no string for servlate


How do you write c program to perform sum of elements of matrix using pointers with functions?

i cant write


How do you run graphics program in C?

pro c language to implement linear search using pointers


What is a pointer in C programming language?

A pointer in C is the address of a variable or function.The advantages of a pointer over using normal variables are:If you pass the pointer to a variable to a function, then that function can modify the value of the variable directly; for example, suppose you want a function to convert a string to lower case. If pointers are not available, then a function call would look like this (in BASIC):NewString = ToLower("This Is A String")What the BASIC compiler does is make a copy of the "This Is A String" string, pass it to the ToLower() function and return a copy back to the caller to be copied to NewString.All these copies make the process slow. In C you can do this:StringPtr = "This Is A String"ToLower(StringPtr)StringPtr points to the string, ToLower() receives the pointer and performs the conversion on the original string without any copying taking place.Function pointers allow C to be used in a more object orientated way; C doesn't support objects, but a structure can contain a collection of data and function pointers so the structure can effectively contain data and the functions needed to process it.The danger of pointers is that they point directly into computer memory and its impossible for the compiler to be certain that you haven't made a pointer point outside of the program memory; the way you find out is when the program crashes when run with an exception error.There is a also slight format error with the way pointers are described in C; for example consider the following function:int Divide(int *a, int *b){int r;r = *a/*b;return r;}Although it looks harmless, the compiler can't tell if the /*b; is introducing a comment or is part of the calculation and most compilers will produce a missing close comment message - although some will silently compile the program - but commenting out everything after the *a!Read more on C from : http://www.indiabix.com/c-programming/index.phpRead more on C Pointer from :http://www.indiabix.com/c-programming/question-answer.php?topic=nqvqmuprt


How do you reverse a string with out using strrev?

By writing user defined function.


What is the use of function in c?

using function we can call the function in the program any where. by using functions we can reduce the code redundancy