answersLogoWhite

0


Best Answer

Here is a page that will teach you about strings and pointers.

www.juicystudio.com/tutorial/c/strings.asp

Just saying String and Pointer don't actually aid us to describe what actually has to be answered .An Array is just repeatation of similar data types and String is as similar repeatation of continious characters in C. A String momentarily differs from a character array in terms of what the representations are for e.g. {'a','b','\0','i','s'}and{'a','b','\0','i','s','\0'}both are character arrays but in Ist "ab " is the string while in IInd "ab is" is as a whole is string for the string to be checked a ordidary way is to check the presence of the '\0' at last of its representation : Means :->check (Stringdef[i]!='\0')?HAS_MORE_CHAR:END_OF_STRING; for pointer validity:-> check (Ptr)?PTR_VALID:NOT_DEFINED; For more resurces just check any of the C material where the pointers are discussed and any misclearity mail me @ rupesh_joshi@sify.com,rupesh.joshi@gmail.com

User Avatar

Wiki User

8y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How do you check strings and pointers in C code?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

Can you tell me a C program to find if the strings are equal using pointers?

It is called strcmp, part of the standard run-time library. Returns 0 if the two strings are equals, non-zero otherwise.


How are the strings passed to a function?

By reference. The name of the string is converted to a pointer (in C/C++) and given to the function as the address of the first element. (In Java, all objects are passed by reference, and there are no pointers.)


In C you use the concept of pointers whereas there are no pointers used in JAVA why?

Pointers in C are generally the thing that gives learners the most trouble. When C code is not written correctly with respect to pointer use, the resulting bugs can often be very difficult to find and correct. On the other hand, pointers are absolutely necessary in some cases.The designers of Java wanted to make programming easier and hence avoided adding pointers to the language. Java does have object references which accomplish much of what pointers accomplish albeit in a safer way.


How c strings are terminated?

c strings are terminated by \0 character


How do you swap two strings in c plus plus?

The most efficient way to swap strings is to point at them, and swap the pointers. Swapping the actual strings is problematic if the strings are of unequal length but impossible when they are also statically allocated. Dynamic strings can always be physically swapped, however it's highly inefficient. If it really must be done, then use a built-in method such as string::swap(). Otherwise just use string pointers and swap the pointers, never the strings themselves. The following example shows how both techniques can be used on statically allocated strings. Example output is show below. #include <iostream> using namespace std; void SwapPointers(char ** pp1, char ** pp2 ) { cout<<"\nSwapping pointers:"<<endl; char * t = *pp1; *pp1 = *pp2; *pp2 = t; } void SwapStatics(char * String1, char * String2, size_t len) { cout<<"\nSwapping static strings:"<<endl; while(len--) String1[len]^=String2[len]^=String1[len]^=String2[len]; } int main() { char s1[] = "one "; char s2[] = "two "; char s3[] = "three "; // Note that the output statements before and after // swapping are exactly the same, proving the strings // have really swapped. cout<<"Original strings:"<<endl; cout<<s1<<s2<<s3<<endl; SwapStatics(s1,s2,sizeof(s1)); cout<<s1<<s2<<s3<<endl; cout<<endl; // We cannot swap s3 with either s1 or s2, because // s1 and s2 don't have the space to accomodate s3. // However, we can use pointers instead: char * p1 = s1; char * p2 = s2; char * p3 = s3; // Again, note that the output statements are the // same before and after swapping, proving the // pointers have swapped. cout<<"Original pointers:"<<endl; cout<<p1<<p2<<p3<<endl; SwapPointers(&p1,&p3); cout<<p1<<p2<<p3<<endl; cout<<endl; // Just to prove the strings didn't swap... cout<<"The strings have not swapped:"<<endl; cout<<s1<<s2<<s3<<endl; cout<<endl; return(0); } Output: Original strings: one two three Swapping static strings: two one three Original pointers: two one three Swapping pointers: three one two The strings have not swapped: two one three

Related questions

Write a c program to copy two strings using pointers?

nahi malum


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

No.


How do you write a C program to copy to strings using pointers?

mystrcpy (char* dest, char* src) { while ((*dest++ = *src++) != '\0); }


Can you tell me a C program to find if the strings are equal using pointers?

It is called strcmp, part of the standard run-time library. Returns 0 if the two strings are equals, non-zero otherwise.


How are the strings passed to a function?

By reference. The name of the string is converted to a pointer (in C/C++) and given to the function as the address of the first element. (In Java, all objects are passed by reference, and there are no pointers.)


In C you use the concept of pointers whereas there are no pointers used in JAVA why?

Pointers in C are generally the thing that gives learners the most trouble. When C code is not written correctly with respect to pointer use, the resulting bugs can often be very difficult to find and correct. On the other hand, pointers are absolutely necessary in some cases.The designers of Java wanted to make programming easier and hence avoided adding pointers to the language. Java does have object references which accomplish much of what pointers accomplish albeit in a safer way.


What is the difference between c plus plus and java programming?

Java doesn't have pointers. C++ has pointers.


What is the source code for attendance record system in c language using pointers functions arrays whichever required?

bmbmbvjmgjmgj


What is stream pointer in c?

C does not have stream pointers.


How c strings are terminated?

c strings are terminated by \0 character


What is unsafe code?

C# provides the ability to write unsafe code. In unsafe code it is possible to declare and operate on pointers, to perform conversions between pointers and integral types, to take the address of variables, and so forth. In a sense, it is like writing C code within a C# program. Unsafe code must be clearly marked with the modifier unsafe, so developers cannot possibly use unsafe features accidentally. When CLR finds this unsafe modifier, the execution engine works to ensure that unsafe code cannot be executed in an untrusted environment.


How do you check the codes?

how can check my i e c code activity/validity