A few questions for practise - while I am away....
When we get into serious C , we are sometimes all at sea while grappling with syntax, standards and good practises.
What is valid may be scorned at by the C-community. Here are a few puzzlers.
1. Is i = i++ + --i legal ?
2. Some C compilers let you use the trailing C++ style comments //.
2. Some C compilers let you use the trailing C++ style comments //.
WHY SHOULD WE NEVER USE THESE IN C PROGRAMS ?
3. Some people like to use the capitalized-first-letter form of naming, others prefer underbars, e.g. GetNextPage() or get_next_page() . Which one do you recommend and why ?
4. What is Microsoft's Hungarian Notation ?
5. What is the output for the following code ?
3. Some people like to use the capitalized-first-letter form of naming, others prefer underbars, e.g. GetNextPage() or get_next_page() . Which one do you recommend and why ?
4. What is Microsoft's Hungarian Notation ?
5. What is the output for the following code ?
main( )
{
char a[ ] = "abcde" ;
char * p = a ;
p++ ;
p++ ;
p[2] = 'z' ;
printf("%s" , p) ;
}
Manoj and Soumen haven't collected their prizes yet.They can do so after 16th of June.
Have a nice day !
I have already posted the answers in earlier post(Because it was not taking comments at that time).I am posting it again for the easiness.
ReplyDeleteAnswers:
(1)i = i++ + --i is legal statement.
(2)It is not ANSI standard, and confuses people as to whether they are looking a C or C++ code.
(3)Capitalized form is mostly preferred,as it is widely used in library functions.It all depends on the programmers choices.
(4)Microsoft's Hungarian Notation is the method of prefixing variable names with their type.
(5)Output : cdz .
Explanation:
#include"stdio.h"
main( )
{
char a[ ] = "abcde" ;
char * p = a ;
/* p is the character pointer initialized to string a */
p++ ;/* Incrementing p which is address */
p++ ;/* Again incrementing p,now p points to c */
p[2] = 'z' ;/*It is overwriting e by z,as p[2] points to e*/
printf("%s" , p) ;/*output = cdz*/
}