CS320 Final

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

Describe the purpose of pointers

-Allows for data to be referenced (shared) amongst a variety of things (functions) -Allows for large sets of data to be referenced without explicitly naming each one

Why do most languages prevent you from accessing variable declared in other functions?

A variable's value is typically placed on the stack, and when a function finishes the stack changes resulting in the value at the memory location non longer being saved for that variable (which means it may be used for something else)

What does the CPU consist of?

ALU(arithmetic logic unit) - does calculation Bus connection to memory registers - memory on CPU

In C/C++, why is it not appropriate to return a reference to a local variable?

After the function returns, the stacks memory may be overwritten

Give at least on way that text based interfaces to an OS (such as a Shell) benefit the end user:

Automation is simpler

In C, why did the designers choose to not implement the data type string?

C does not support OOP

How is C different than C++?

C requires thinking primarily in terms of actions, whereas C++ allows us to think in terms of things

How do we create new data representations of the ones and zeros in Object Oriented Programming languages?

Define a class

Defining a class in an object oriented language does what?

Defines a novel data type that the compiler can now work with

All programming languages share the same fundamental types. (T/F)

False

Shell scripting languages only run on Unix/Linux/BSD machines

False

In C, why did the designers choose to require a format string as an argument to scanf?

Format strings tell the functions how to attempt to interpret the data provide

Which of the following is MOST important when selecting a language for a project/application?

It depends. There is no single correct answer

Why would an organization choose to write an application in Java?

It is capable of running on multiple platforms without rewriting the code, it is capable of implementing very large software projects because of its design features, and it has a large number of libraries built in that simplify many tasks

Why would we write a program in Java that would run faster than a program written in C/C++?

Java contains many packages that may implement an optimized version of an algorithm, we aren't necessarily good programmers our implementations have flaws, and Java requires a virtual machine that would have to interpret java byte code

Which best describes imperative programming?

Languages where the programmer specifies how to solve problems

Describe the pertinent differences between the C++ new and the C malloc

New is more typesafe (but not completely) than malloc. New ensures that the data is initialized by the constructor

What language features would you look for when developing a large scale project? Also indicate why for each

Object oriented programming allows groups to work effectively and protects implementations from inadvertant misuses

Where do local variables have their memory placed by compilers (in most languages)?

On the stack

What is the purpose of shell scripting languages?

Organizing the actions of many smaller purpose driven applications to accomplish larger tasks

What is the purpose of pointers?

Pointers allow you to access many elements of the data through a single variable name and pointers allow different sections of a program to have access to the same memory

What is scope?

Scope is the region in which a variable's name is valid for use

Why would you want to specify a memory allocation on the heap in C/C++?

So that it is available after the function finishes

Why are shell scripting languages usually not appropriate for large scale application?

The interpreter does not provide very good debugging information

How are large scale projects (like Operation Systems) developed in C without OOP?

The problem is broken up into smaller chunks with purpose driven software written for each chunk

When would large scale projects (like Operating Systems) use a scripting language during development?

To automate certain parts of the build/compile system and to automate a test suite to prevent regression errors (Run a test suite to check for errors)

Why do we define classes in object oriented programming languages?

To create new data types and abstactions

Why do we use malloc and new?

To dynamically allocate memory on the heap

Why do we use shell scripting languages?

To organize the execution of several different programs at once and to automate complex or repetitive tasks

Why is it important for a programmer to understand scope?

To understand when variables will be available for use/how to access a piece of memory from another scope

Why is it important for a programmer to understand scope?

To understand when variables will be available for use/how to access a piece of memory from another scope HIS DEF: programmer must know which value is used by name in each scope

When language designers make new programming languages, they typically design the languages such that variables have limited scope. Why do they choose to make variables have limited scope?

Two different functions/classes can use the same variable name without conflicts

When discussing variables and values we often talk about using the correct type. What is a data type?

Types tell the compiler and the CPU how to interpret the ones and zeros in memory

When discussing variables and values we often talk about using the correct type. What is a data type?

Types tell the compiler and the CPU how to interpret the ones and zeros in memory HIS DEF: they dictate how much memory to allocate and specifies how data should be interpreted

What is the result of local variables having their memory placed by compilers (in most languages) on the stack?

Variables have limited scope

Why do we typiccally write Operating Systems in C, instead of an OOP language like C++ or Java?

We want to keep as close to the bare metal abstractions as possible. We do not always want to introduce new abstractions to these concepts

When and why would you use a shell scripting language?

When: if the problem is solvable using a collection of smaller tools Why: faster to implement, reliability of using existing code base

In C, as a programmer, using char arrays instead of strings has a unique benefit, what is it?

You can break the abstraction of the ascii characters and use them as either numbers or characters

function

a procedure that cannot modify state (implicit, global, local dont exist)

scanf("%d...", &x...) what is &x?

a reference; passes a pointer to modify the actual x

pointer

a variable whose value is the address of another variable special type of variable that can hold an address

examples of abstractions

abstraction of integers vs. 2's complement printf

malloc

allocates memory on heap

pass - by - reference

arguments are references to value if you modify one, you modify both (not with C)

pass-by-value

arguments for procedures (functions) are passed as copies of the real value (C)

sub

binary operation 1) pop two values 2) subtract 2nd pop value from the 1st pop value 3) push the result onto the computational stack

procedural

built in mechanisms for calling subroutines

C DATA TYPES: char int float double pointer

char - 1 byte int - 4 bytes float - 4 bytes double - 8 bytes pointer - 32 bits (4 bytes) or 64 bits (8 bytes)

two types of OOP

class based and prototype based

3 parts of stack machine

computation stack operators (ex add) memory (ex RAM)

declarative programming

construction of data and queries the programmer asks questions (ex. how many students have first names that are less than 3 letters?) most common in databases (ex. SQL)

structured programming languages

control flow structures exist ex. if, while, for, switch

data driven programming

data decides the behavior of the application goal: code does not need to change to affect behavior

OOP

deconstruction of problems into constituent parts think in terms of things

How can you increase the variable?

dont put it on the stack, put it on the heap

logical programming

expert system; "deduce" rules and facts from rules and facts

examples of data driven programming

facebook - your experience is driven by the data you have videogames

what is a variable?

is a value that can change, depending on conditions or on information passed to the program all variables are located on the stack

which best describes procedural programming?

languages that allow for calling other portions of code

which best describes structural programming

languages that have control structures like if/else and for

which best describes declarative programming

languages where the programmer specifies which problems to solve

what type of data structure is a stack

last in, first out

prototype based OOP

make objects

classed based OOP

makes blueprints

Why do we want to allocate memory on the stack? (in C)

memory allocated on the stack has a lifetime limited to the functions that declares it

selective branch

pop some value if value == #, go to else, skip

what things can a stack do

pop, push, size (how big it is), build/create/make

In C, as a programmer why must you specify a format string when using printf?

printf is written such that it requires the format string as input

define method

procedure that operates on an object; only for OOP a procedure that modifies implicit state (global: has a this reference)

event driven

process of writing procedures to handle specific events you dont write main function dont require a lot of state (the event should contain all the info needed)

what am i doing when I push?

put value on the array

When would using a declarative language be useful (one good situation is enough)?

query a database

sizeof(int)

returns size of data type you choose; in this case int

stack machine

simplest conceptual turing complete computation engine

abstractions

the ability to use a concept without understanding how it works

what data do I need?

the array to put the data in the index to put the data at the capacity

turing machines

the simplest mathematical construction of an arbitrary computation engine anything we can compute is computable by a turing machine

example of logical programming

traditional/symbolic AI videogames feeling repetitive

three operators

uninary: one operand binary: two operand terary: three operand

imperative programming

what you write is what happens the programmer solves problems (writing explicit steps)

In what situations is it incorrect to return a pointer to a piece of data?

when the data was declared in currently returning function when the function that is declaring the data you are pointing is ending

computation stack

where we store data for operators push-add data to top pop-take data off top

Are stack machines CPU's

yes

what does it mean when your malloc fails?

you are out of memory


Ensembles d'études connexes

Property & Casualty Basics (Ohio)

View Set

Entrepreneurship I: What's the Objective?, Razzle Dazzle, SEM 3 UPDATED TEST(FOR REAL)

View Set

MCB 2004L mastering questions FINAL

View Set

FCE Practice Tests 3+4 Sentence transformation

View Set