-
-
-
Why is assigning to string as given below not allowed?
Consider the code:main() { char s[8] = “Exforsys”; } The above code is not allowed in string handling concept. This is because strings are represented in C programming language as arrays and therefore assigning as above arrays is not allowed.One can make use of strcpy() which is a string handling function present in string.h header file for this purpose. So the above code can be written as#include...
-
">
What happens when the following code is executed? #include <stdio.h> main(){ char *s; if (s == "10") { printf("string matches"); } }
In the above code the operator == is used to compare the value of string. But this is not allowed. This is because in C program string is represented as array of characters. So the operate like comparison, assignment and so on cannot be used to manipulate array as whole. So the above code does not work. In order to achieve the string comparison instead of using == C programmers must use function named...
-
What is the return value from printf() function?
printf function always returns the number of characters printed by the printf function. Let us see this in brief with an example: main() { int a=10; printf(“%d,printf(“%d %d %d,a,a,a)); } In this above program the inner printf is first called which prints three times the value of a, with space between each value namely 10 10 10. So 5 characters namely 3 value of a namely...
-
What is the default return value of a function?
The default returns value from a function in int. In other words generally unless explicitly specified the default return value by compiler would be integer value from function. So when a programmer wants other than integer values to be returned from function then it is essential that the programmer takes some steps in doing this namely: 1. Mention eth return type in the calling function and 2....