Pascal (i think) passing by name, reference, value and value-result

This may be kind of long but hopefully not too hard. This is the Pascal section so can you tell me if this program segment is written in Pascal or not (I don't know this language by the way...obviously).

program Main (...);
     var Y: integer;
     procedure P(X:integer);
          begin X := X+1; write (X,Y) end;
     Y :=1; P(Y); write(Y)

Is this in Pascal? This matters only so I ask this question in the right section. I don't know either way. What I do need to know is how to determine the following:

I know that passing by value means passing the parameter to the formal parameter; that passing by reference means that a pointer is used or has the potential to be used by a subprogram;  passing by value-result is when the formal parameter is a local variable with the same data type as  the parameter; and that passing by name is a subprogram call that substitutes for the body of subprogram.

 I know in theory what all of these mean but  because of my ignorance in Pascal, how do I follow the execution of these 4 types of parameters? I know that if you follow the execution of this segment (by transmitting Y to P) using each one of these methods (by reference, by name, etc.), the program will output several numbers.

Can you give me tips/resources/any help on how to determine what the output of this program segment would be using each of these four methods?  If this segment is not in Pascal can you tell which language it is so I can ask this question in the right section?

I appreciate it so much. Thank you :)

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

It certainly looks like pascal!

The rest of it looks like homework though!

By value:    Procedure X(aValue:integer);
By Reference:  Procedure X(var aValue:integer);
collegegirlAuthor Commented:
This is why I asked for tips/help/resources not for answers to the problem. I'm not asking you to do it for me but to help me understand how the execution works and how to determine the output using those methods because these concepts are hard for me to understand.

I don't really understand what: Procedure X(aValue:integer); and Procedure X(var aValue:integer); means? Can you give more explanation on this in layman's terms?  


just try google with the keywords  "by reference pascal function procedure" to get
many info from the net.
eg. read this short link , It will answer all of your questions:
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

TO start with, yes thats pascal!

A procedure is a small chunk of code set to perform a certain task such as input a name etc. that you can call to save time when your coding. e.g. a section called read_name then call it with read_names; is much faster than having a plethora of readln(); all through the code.

where you have Y : Integer its just making Y a value which can only hold whole numbers (integers), the same with X : Integer inside the procedure.

procedure P(X:integer);
Y :=1; P(Y); write(Y);

I think those two lines are confusing you the most.

To step it through, i will comment the code for you (with {})

program Main (...);                     {this just names the program name}
     var Y: integer;                       {declaring the value Y, as an variable integer value, it can have any value set to it, that is a whole number}
     procedure P(X:integer);         {opens the procedre, called P, with the parameter X set as an integer for use only inside that procedure}
          begin X := X+1; write (X,Y) end; { simple mathematical operations}
     begin                                    {this is where the actual program starts, the procedure isnt processed until it is called}
     Y :=1; P(Y); write(Y)             {it declares the variable integer Y, to a value on 1, then it calls the procedure P and passes the value Y to the procedure. the procedure received the value Y, and it can process it how it wishes, then the value of Y is passed back to the main program, where it is written to the screen}

Some basic pascal syntax:

var --- declare a letter/name to be allowed to have values assinged to it, can be integer, real, string, and others
begin...end --- all programs, and procedures must be wrapped with begin and end to show where they are to be executed
write ----output data to teh screen

Hope that explains

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Pascal keeps values of the variables on program stack.

Declaration of the variable means that compiler entering the block of the code (where variable is declared) creates the variable by allocation of proper amount of memory on the program stack. Then the variable can be accessed by it's name.

Declaring by the value:
Procedure X(aValue:integer);

When entering the procedure, pascal allocates memory for the new variable aValue. When procedure ends aValue is destroyed.
After new variable is created it is filled with the value passed in procedure call.
X (1234);
Means aValue has an initial value of 1234.

Declaring by reference:
Procedure X(var aValue:integer);

When entering the procedure no memory allocation is performed. All operations with aValue are performed on the variable passed wit procedure call:
X (PassedVariable);
Every operation on aValue is in the fact operation with PassedVariable.
The 2 last of your parameter types are not pascal ('value result' and 'name'). They look like the earlier programming language Algol.

Pascal was very much derived from Algol, but Wirth chose to scrap those two as they answer only to a theoretical need. In practice only college professors could find a use for them. (it is worth noting that Java has now scrapped 'by reference' also. Simplicity is a valid goal in itself).

The code you show could be Pascal or Modula or some other language i dont know. Programmmmming languages borrow a lot from eachother.

regards JakobA
collegegirlAuthor Commented:
Thank you so much for your help

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.