c program

Discussion in 'Meet and Greet' started by A.saikumar, Sep 1, 2011.

  1. A.saikumar

    A.saikumar New Member

    Joined:
    Sep 1, 2011
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    1. what is the error in the following sequence of program.

    int i1;
    switch(i1)
    {
    printf("The value of I1 is :");
    case 1: printf("%d",i1);
    break;
    case 2: printf("%d",i1);
    break;
    default : printf("Invalid entry");
    }
     
  2. A.saikumar

    A.saikumar New Member

    Joined:
    Sep 1, 2011
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    need quick reply
     
  3. NewsBot

    NewsBot New Member

    Joined:
    Dec 2, 2008
    Messages:
    1,267
    Likes Received:
    2
    Trophy Points:
    0
    variable has not been initialized.
     
  4. gpk kishore

    gpk kishore New Member

    Joined:
    Jun 30, 2011
    Messages:
    82
    Likes Received:
    0
    Trophy Points:
    0
    when u have declared i1 has int no memory is allocated for that
    you must initalize it as for eg.., int i1=5;
     
  5. NewsBot

    NewsBot New Member

    Joined:
    Dec 2, 2008
    Messages:
    1,267
    Likes Received:
    2
    Trophy Points:
    0
    Completely wrong. when you declare int i1 memory is allocated but not initialized. i1 is not a pointer but a variable here.
     
  6. gpk kishore

    gpk kishore New Member

    Joined:
    Jun 30, 2011
    Messages:
    82
    Likes Received:
    0
    Trophy Points:
    0
    sir my intention of writing that is memory is allocated only when it is defined
    when we have given int i 'i' value and its address vary from compiler to compiler
    so i have written in the above way
     
  7. imported_mehul

    imported_mehul New Member

    Joined:
    Oct 13, 2011
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    Dear Mr. gpk kishore

    Thanks for your post on the forum. They have been very helpful with my assignment. You are a very good computer programmer and really appreciate your help.
    Carry on your good work

    Mehul :)
     
  8. gpk kishore

    gpk kishore New Member

    Joined:
    Jun 30, 2011
    Messages:
    82
    Likes Received:
    0
    Trophy Points:
    0
    Thanks mehul
    for your complement
     
  9. imported_Meghana

    imported_Meghana New Member

    Joined:
    Mar 8, 2011
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    i1 is not initialised.so switch statement won't be able to know what the condition is.the whole program would be meaningless.
     
  10. ophelia.2010

    ophelia.2010 New Member

    Joined:
    Oct 18, 2011
    Messages:
    14
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    student
    Location:
    london
    There's no need to initialize!!! You'll first have to get the value from the user so that the values can be compared.so it goes like this

    int i1;
    scanf("Enter the value of %d",i1);
    switch(i1);
    ....................
    Then the program will be perfect!!!
     
  11. ophelia.2010

    ophelia.2010 New Member

    Joined:
    Oct 18, 2011
    Messages:
    14
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    student
    Location:
    london
    OOPS!!! SILLY mistake!!! that must be

    scanf("Enter the value of %d",&i1);

    You'll get it now!!!
     
  12. gurpreet guppi

    gurpreet guppi New Member

    Joined:
    Oct 19, 2011
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    0
    Code:
    #include<stdio.h>
    #include<conio.h>
    void main()
    {
     int i;
     printf("The value of I is :");
    scanf("%d",&i);
    switch(i)
    {
    
    case 1: printf("%d",i);
    break;
    case 2: printf("%d",i);
    break;
    default : printf("Invalid entry");
    }
    getch();
    }
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice