Declaring Variables

Keeping in mind that no string variables exist in C, declaring variables in C is about as simple as declaring them in Visual Basic. Consider the following section of a main() function:

main()
{
  char initial;
  mt age;
  float amount;

This code declares three variables: initial, age, and amount. They hold three different types of data: a character, an integer, and a floating-point value. These variables are local to the function and cannot be used outside main(). (You can declare variables before main(), and those variables are known as global, but global variables are generally not recommended.)

C does not initialize variables to zero as Visual Basic does. The assignment statement works just as it does in Visual Basic. You can ...

Get Absolute Beginner's Guide to Programming, Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.