Difference between two strings
I am currently working on a project to develop a library in C. I finally found a mistake that I did not expect and it's hard to explain.
Code:
# include <stdlib.h>
# include <stdio.h>
int main ()
(
char * string1 = "text", string2 [] = "text";
printf ( "% d", sizeof (string1));
printf ( "% d", sizeof (string2));
return 0;
)
I thought we would get the same result but not: string2 is greater than string1. Is there any difference between these 2 syntax ... Thank you for your help
Re: Difference between two strings
string1 is a pointer: sizeof gives the size of the pointer. string2 is an array: sizeof gives the size of the table, because in string2 [] = "text" it is created automatically.
In the first case, you're pointing a pointer to a string literal. In the second case, you initialize an array with the string.
Re: Difference between two strings
Check this example :
Code:
import org.apache.commons.lang.StringUtils;
public class String1 {
public static void main(String args[]) {
System.err.println(StringUtils.getLevenshteinDistance("gov", "govern"));
}
}
Re: Difference between two strings
A string is a sequence of characters. Any sequence or set of characters defined within double quotation symbols is a constant string, Basically, you would cycle through each character in one string, and compare it to the corresponding character in the other. If the string or the character doesn't exist, then there is a difference.
Re: Difference between two strings
what is the means of ** 5.2 ** in this line and why we using this?
printf("%5.2f",float);
Re: Difference between two strings
Quote:
Originally Posted by
aasheeshk
what is the means of ** 5.2 ** in this line and why we using this?
printf("%5.2f",float);
When you are using %5.2, then you can easily come to know that all prices less than $1000 will line up on the decimal point and be good to read.