Tuesday, November 18, 2014

Simple language programming in C / C ++




Language of the input is usually taken as a string. Type-specific data is then converted. If you want to print the string is printed as anything. Why do whatever Karakorum the user programs, it is converted to string some time. This article uses a variety of string, such as the return type of the function, input / output, functions, etc. are discussed.


The return type of the function as a string
The function returns the data type can be used as a string. However, one thing is noticeable, caller function value points to the garbage. For example:
char * funcX ()
{
char str [] = "A sample string";
return str;
}
Function at compile time the compiler does not have any errors in the data will not be shown to the caller function properly. The work function of time will keep the data stack, it will not be the end of the work function. Function so that the caller will receive an IP address, which will be garbage data points. The function returns the string that should be taken at the time. The caller of the function determines the required space can be sent kalda function. For example:
funcX (char * str)
{
strcpy (str, "String from funcX")
return st;
}
This function can be used. This function returns the address of the main str, so ptr data point does not have any garbage. Or it can be done without having to use the function myalaka kalda function. For example:
char * funcX ()
{
char * ptr;
ptr = malloc (32 * sizeof (char));
strcpy (ptr, "String from funcX");
return ptr;

No comments:

Post a Comment

No Samp