Intro2ProgrammingWeek2

Variable declaration variables are place holders for

Info icon This preview shows pages 2–4. Sign up to view the full content.

View Full Document Right Arrow Icon
Variable Declaration Variables are place holders for data a program might use or manipulate. Variables are given names so that we can assign values to them and refer to them later to read the values. Variables typically store values of a given type . Types generally include: Integer – to store integer or “whole” numbers Real – to store real or fractional numbers (also called float to indicate a floating point number) Character – A single character such as a letter of the alphabet or punctuation. String – A collection of characters In order to use a variable within a program, the compiler needs to know in advance the type of data that will be stored in it. For this reason, we declare the variables at the start of the program. Variable declaration consists of giving a new name and a data type for the variable. This is normally done at the very start of the program. In the following example programs, variables of different types are declared and used in the programs. Language Example program “C” #include <stdio.h> void main() { int age; float salary; char middle_initial; age = 21; salary = 29521.12; middle_initial = "K"; printf("I am %d years old ", age);
Image of page 2

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
printf("I make %f8.2 per year " salary); printf("My middle initial is %c ", middle_initial); } Pascal program myexample (output); var age: integer; salary: real; middle_initial: char; begin age := 21; salary := 29521.12; middle_initial := 'K'; writeln('I am ', age, ' years old'); writeln('I make ', salary, ' per year'); writeln('My middle initial is ', middle_initial); end. Oracle PL/SQL CREATE OR REPLACE PROCEDURE myexample AS age NUMBER; salary NUMBER; middle_initial CHAR(1); BEGIN age := 21; salary := 29521.12; middle_initial := 'K'; DBMS_OUTPUT.PUT_LINE('I am ' || age || ' years old'); DBMS_OUTPUT.PUT_LINE('I make ' || TO_CHAR(salary, '99999.99') || ' per year'); DBMS_OUTPUT.PUT_LINE('My middle initial is ' ||
Image of page 3
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern