-
">
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 happens when a variable is not initialized in main function?
When a variable is not initialized in main function it contains garbage value. This can be well seen from the example below main() { int x; printf( “%d”,x); z= sample() } sample() { printf(“Testing program”); } Output is x=80 Testing program The above program prints a garbage value and the output testing program .This is because the variable...
-
How is C++ a higher level of C?
C++ is an improved and higher level of C with more features and abilities built in it. Apart from the regular features of C the other features which C++ possess which makes it a higher level of C are classes, objects, constructors and destructors, virtual functions, concept of polymorphism, abstract classes, able to provide access levels like public, private and protected for members, friend functions,...