Thread: A new userand learning c from scratch trying to understand some questions

  1. #1
    Registered User
    Join Date
    Jan 2017
    Posts
    6

    Lightbulb A new userand learning c from scratch trying to understand some questions

    Hi friends,

    Kindly be informed that I recently start to understand c programming. i have created hello world program and can understand if else statement. I want to understand for loop.
    I have some questions:

    1) In for loop why there is always written i=, i< and i++ in a bracket?
    what is i and why there is < and ++ and sometimes i+1 sign

    2) why in c there is always int main() in starting the program?

    3) what is getch() and return statement?

    Any answer and simple explanation to a new user like me will be highly appreciated.

    With regards,
    Soumya

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Jan 2017
    Posts
    6
    Thanks Salem for the answer. But where should I use for loop and where should I use do while loops? what is void main()and getch()?

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Use a for loop when the number of iterations is known in advance.

    Use a while loop if the number of iterations might be zero.

    Use a do-while loop if the number of iterations is at least one.

    void main is a nonsense introduced by lazy DOS programmers.
    main is standardised as returning int, and always returned int on real operating systems.

    getch() isn't a standard function, it comes from conio.h, which is another piece of brain damage from the DOS era.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  5. #5
    Registered User
    Join Date
    Jan 2017
    Posts
    6
    Thanks Salem , It seems no other person in this forum even cares to answer my( I am a Beginner) question other than you. Are there any solved examples and programs of for, while and do while loops?Which websites produce numerous solved examples in C?

  6. #6
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Looking at solved problems is like going into a restaurant to sample the food in the hopes it will make you a great chef.

    It won't.

    It's a hard road, but the only way to really understand this stuff is by writing your own programs.
    An important part of this learning is seeing how programs fail, so you know how to fix things the next time it happens.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  7. #7
    Registered User
    Join Date
    Jan 2017
    Posts
    9
    Hi Soumya, a search "loop exercises in C" in google should produce plenty of results for you to look at. But as Salem advised, writing your own code is the best way to go. I am a beginner too and learning my way through writing simple codes. Start with very simple program such as; a program to print incremental value up to 100. Example;- int value = 1, now with every loop iteration, the value should increase by one and gets printed.

  8. #8
    Registered User
    Join Date
    Jun 2011
    Posts
    4,513
    Quote Originally Posted by soumyatome View Post
    It seems no other person in this forum even cares to answer my( I am a Beginner) question other than you.
    Typically, when a regular sees that a question has been sufficiently answered, they do not bother posting essentially the same answer.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Learning C: Questions About Standards
    By DreamThink in forum C Programming
    Replies: 9
    Last Post: 02-15-2013, 07:28 AM
  2. noobish some-questions (first day learning c++)
    By cable in forum C++ Programming
    Replies: 4
    Last Post: 07-06-2011, 05:07 AM
  3. Learning C++ alone, A few questions
    By LegendsEnd in forum C++ Programming
    Replies: 6
    Last Post: 05-06-2007, 02:13 PM
  4. do not understand the questions
    By winlinux in forum C Programming
    Replies: 2
    Last Post: 02-27-2005, 04:36 AM
  5. Some questions about learning languages
    By Zewu in forum A Brief History of Cprogramming.com
    Replies: 13
    Last Post: 03-08-2003, 06:46 AM

Tags for this Thread