Right Click to Search

Friday, May 21, 2024

C Programming Puzzle : Switch and Variable name Validity




This Program at a First Glance is error Free but It has one Serious Bug , Will you remove it without compiling it ?
#include<stdio.h>
void OS_Solaris_print()
{
        printf("Solaris - Sun Microsystems\n");
}
void OS_Windows_print()
{
        printf("Windows - Microsoft\n");
}
void OS_HP-UX_print()
{
        printf("HP-UX - Hewlett Packard\n");
}
int main()
{
        int num;
        printf("Enter the number (1-3):\n");
        scanf("%d",&num);
        switch(num)
        {
            case 1:
                   OS_Solaris_print();
                   break;
            case 2:
                   OS_Windows_print();
                   break;
            case 3:
                   OS_HP-UX_print();
                   break;
            default:
                   printf("Hmm! only 1-3 :-)\n");
                   break;
        }
}
Output :
case 3:
                        OS_HP-UX_print();
                        break
  1. OS_HP-UX_Print i not valid Identifier ( Function name )
  2. It has dash (-) in between.

Tags / Keywords : |

Stumble
Delicious
Technorati
Twitter
Facebook

0 Comments:

Post a Comment

Your Feedback :This is Growing Site and Your Feedback is important for Us to improve the Site performance & Quality of Content.Feel Free to contact and Please Provide Name & Contact Email

 

Learn C Programming Copyright © 2010 LKart Theme is Designed by Lasantha, Free Blogger Templates