Programming Language Concepts
Let’s finish this series off right: with another 141 questions. I think 781 questions are a good starting point in your Computer Science exploration. Check out the links at the bottom of the page for the previous 640 questions.
641. True or False? Pointers in C can point to any variable.
– True
642. How do you get the address of a variable in C?
– with the ampersand symbol (&)
643. If the pointer is pointing to an array, what are the 3 forms of pointer arithmetic supported in C and C++?
– Adding an integer to a pointer
– Subtracting an integer from a pointer
– Subtracting two pointers
644. True or false? An array name not followed by subscripts can be used as a pointer to the first element of the array.
– True
i.e.
int list[10];
int *ptr;
…
ptr = list;
…
so you can do
…
*(ptr + 1)
*(ptr + index)
ptr[index]
645. True or False? In C and C++, pointers can point to a function.
– True
646. C and C++ allow pointers of type ______, which can point at values of any type.
– void *
647. What is the return type of the function malloc?
– void *
648. In Java, a value of a reference type is like a pointer except that it must refer to an ______.
– object
649. True or false? Arithmetic cannot be performed on references.
– True
650. What is a reference in C++?
– an alias for another variable
651. True or false? A reference type in C++ must be initialized at the time it’s bound to storage and cannot refer to any other variable during its lifetime.
– True
652. What are reference types mainly used for?
– Declaring parameters
653. True or False? C# includes both the reference of Java and the pointer of C++.
– True
654. For a subprogram to use a pointer in C#, you must include the _____ modifier.
– unsafe
655. True or false? All variables in Smalltalk, Python, Ruby, and Lua store references and are implicitly dereferenced.
– True
656. Name one area where pointers are beneficial.
– writing device drivers
657. Name two proposed solutions for the dangling pointer problem.
– the use of tombstones
– the use of locks-and-keys
658. What is a tombstone?
– Pointer variables point to a tombstone cell that in turn points to the heap-dynamic variables.
659. True or false? When the heap-dynamic variable is deallocated, the tombstone remains.
– True ,but it’s set to nil.
660. What is the locks-and-keys approach?
– A pointer is stored as a (key, address) pair where the key is an integer value and each heap-dynamic variable has a header cell that store an integer lock value. When the heap-dynamic variable is allocated, a lock value is created and placed both in the lock cell of the heap-dynamic variable and in the key-cell of the pointer. When the pointer is dereferenced, the key value of the pointer is compared to the lock value of the heap-dynamic variable.
661. What is the best solution to the dangling pointer problem?
– To provide implicit deallocation for heap-dynamic variables that are no longer useful
662. How does Java take care of the deallocation of heap-dynamic variables?
– Implicitly using their garbage collector.
663. _______ are the fundamental means of specifying computations in programming languages.
– Expressions
664. Operator evaluation is governed by __________ and ___________ rules.
– associativity and precedence
665. Most of the characteristics of arithmetic expressions in programming languages were inherited from ________.
– mathematics
666. In programming languages, arithmetic expressions consist of what?
– operators, operands, parentheses, and function calls
667. What are the three types of operators
– Unary: one operand
– Binary: two operands
– Ternary: three operands
668. In most programming languages, binary operators are _______, appearing between their operands.
– infix
669. Unary operators can be either ______ or _______.
– prefix or postfix
670. True or false? The value of an expression may depend on the order of evaluation of the operators in the expression.
– True
671. The operator precedence rules of the common language are nearly all the same and include:
– 1. Exponents has the highest precedence
– 2. Multiplication and division have lower precedence than 1
– 3. Addition and subtraction have lower precedence than 2.
672. What is a unary plus operator called?
– identity operator
673. Why is the unary plus operator called the identity operator?
– Since it usually has no effect
674. True or False? In Java, unary plus and minus cause the implicit conversion of short and byte operands to int type.
– True
675. Which language has a single level of precedence?
– APL
676. When an expression contains adjacent occurrences of operators with the same precedence, __________ rules determine which operator is associated first.
– associativity
677. An operator can either have ______ or ______ associativity.
– left or right.
678. True or False? Visual Basic’s exponentiation operator is left associative.
– True. Most languages are right associative
679. True or False? In APL, the order of operator evaluation is determined entirely by associativity, which is right to left for all operators.
– True
680. Why are floating point numbers often not associative?
– Overflow problem
681. How do you override normal precedence and associativity rules?
– parentheses
682. How are arithmetic and relational operators implemented in Ruby?
– as methods since Ruby is a purely Object-Oriented language
683. True or false? Operators in Ruby can be overridden.
– True
684. In Lisp, operators are _______.
– functions
685. What’s the ternary operator used for?
– to form conditional expressions in C based languages
686. What is a side-effect?
– the result when an operator or function call performs some other action in addition to returning a value i.e. int j = ++i + i; What is j? depends on the associativity
687. A program has the property of ______ ______ if any two expressions with the same value can be substituted for each other without affecting the program’s behavior.
– referential transparency
688. What is operator overloading?
– Allowing the operator to have multiple meanings
689. What happens when an overloaded operator is used in an expression?
– The compiler examines the types of operands to determine the correct meaning of the operator
690. Type conversions are either _______ or ________ and can be explicit or implicit.
– narrowing or widening
691. What is a narrowing conversion?
– converts a value to a type that cannot store even approximations of all the values of the original type. i.e. int to byte
692. What is a widening conversion?
– converts a value to a type that can include at least the approximations of all the values of the original type. i.e. int to double
693. True or false? Narrowing conversions are safe.
– False
694. What are implicit type conversions called?
– coercion
695. What are explicit type conversions called?
– casts
696. What is a mixed-mode conversion?
– operators can have operands of different types
697. Why does Java coerce byte variables into integers before an arithmetic operation is performed?
– architecture. There’s a way to add integers together, but not bytes.
698. Why are casts placed in parentheses?
– because type names may consist of more than one word: i.e. long double
699. When does overflow occur?
– When the result of an operation is too large to store in the designated amount of memory
700. When does underflow occur?
– When the result of an operation is too small to represent.
701. What is another word for a run-time error?
– exception
702. True or false? In Java, floating point division by zero is an error.
– False. Infinity is a well-defined value
703. A _______ ________ compares the values of its two operands.
– relational operator
704. What is the value of the relational expression normally?
– Boolean
705. What is the purpose of === operator in PHP?
– the “is identical to” operator prevents type coercion
– i.e. “7” == 7 is true but “7” === 7 is false
706. How to prevent coercion in the relational expression In Ruby?
– instead of using ==, use eql?
707. True or False? C based languages give OR a higher precedence than AND.
– False. AND gets higher precedence than OR
708. Prior to C99, C had no _______ type. Instead, numbers were used.
– Boolean
709. In C, ______ is considered false.
– zero (all other values represent true)
710. With _______ ________ _________, the value of an expression is determined without evaluating all of its sub-expressions.
– short-circuit evaluation
711. When can a short-circuit expression cause an issue?
– If a Boolean expression contains a side-effect, the side-effect may not occur
712. The ______ ______ _______ combines assignment with some other operation.
– compound assignment operator (i.e. sum+=value)
713. Which language introduced compound assignment operators?
– ALGOL 68
714. True or False? The expression -count++ is interpreted as –(count++), not (-count)++.
– True
715. Assignments are ______ associative.
– right
716. True or False? Java and C# allow only Boolean expressions in if statements.
– True
717. Give an example of a multiple-source assignment statement in Perl.
– ($first, $second, $third) = (20, 40, 60);
718. In ML, how are names bound to values?
– using val (i.e. val cost = quantity * price;)
719. True or false? Java and C# allow mixed-mode assignments if the required coercion is either widening or narrowing.
– False. Only widening
720. What are the two capabilities that most programming languages need?
– Select from among alternative control flow paths
– Repeatedly execute sequence of statements
721. What are the statements that provide the 2 capabilities called?
– Control statements
722. What is a control structure?
– a control statement and the collection of statements whose execution it controls
723. ________ and ________ proved in 1966 that all algorithms could be expressed using only two control statements: one for choosing between two control flow paths and one for logically controlled iteration.
– Bohm and Jacopini
724. What is the unconditional branch statement called?
– goto
725. True or false? Multiple exits from a control structure pose a danger.
– False
726. A ______ ________ provides a way of choosing between two or more execution paths in a program.
– selection statement
727. What are the two general paths that selection statements fall into?
– two way and n-way
728. If parentheses are omitted in control expressions, what is normally used?
– a keyword marker such as then
729. In Ruby, the entire if construct is terminated by the word _____.
– end
730. How does Python specify compound statements?
– by using indentation
731. In Java, the else clause is always paired with the _______ previous unpaired then clause.
– nearest
732. True or False? In the functional languages ML, F# and Lisp, a selector is not a statement; it is an expression that produces a value.
– True
733. In F#, when an if construct has no else clause, the then clause must return a value of the ____ type. This type has only one value, which is written _________.
– unit
– ()
734. A _____-__________ statement allows the selection of one of any number of statements or statement groups.
– multiple-selection
735. What is an example of a multiple-selection statement in C#?
– switch
736. To logically separate code segments in a switch, an _______ _______ much be used; C’s _____ statement is an example and exits the switch statement
– explicit branch
– break
737. True or False? In C#, implicit execution of more than one segment of a switch statement is allowed.
– False. Only one.
738. In C#, the last statement in each selectable segment ends with either a _____ or a _____.
– break
– goto
739. True or False? C# allows the control expression and case labels to be strings.
– True
740. True or False? In PHP’s switch statement, the case values can be any scalar types.
– True
741. Ruby’s multiple-selection constructs are called _____ ________.
– case expressions
742. True or false? Perl, Python and Lua do not have multiple-selection statements.
– True
743. What is the best implementation technique of a multiple-selection statement?
– branch table (or jump table)
744. In a branch table, the ______ of the table are the case values.
– indices
745. In a branch table, the _____ of the table are the segment values.
– elements
746. How are cases matched in a branch table?
– array subscripting
747. Name two other ways to implement a multiple selection statement.
– binary search and hash table
748. What is Scheme’s multiple selector called?
– COND
749. In Scheme, when using COND, the predicates are evaluated in order until one evaluates to ____.
– #T
750. True or False? When a Scheme COND expression that follows the predicate is evaluated it is returned as the value of COND.
– True
751. True or False? In none of Scheme’s COND predicates are true, and there is an ELSE statement, it’s expression is evaluated and the value is returned?
– True
752. What happens when none of the predicates are true and there is no ELSE in Scheme’s COND?
– COND returns an unspecified value
(COND
((> x y) “x is greater than y”)
((< x y) “y is greater than x”)
(ELSE “x and y are equal”)
)
753. An ______ _______, or loop, causes a statement or collection of statement to be executed zero, one or more times.
– iterative statement
754. The ______ of a loop is the collection of statements whose execution is controlled by an iterative statement.
– body
755. What is a pretest loop?
– a loop that tests the condition for loop completion before the loop body is executed.
756. What is a posttest loop?
– a loop that tests the condition for loop completion after the loop body is executed.
757. A counter controlled loop has a ______ ________ in which the count is stored.
– loop variable
758. What are the three parameters that the counter controlled loop also has
– Initial value of the loop variable
– Terminal value of the loop variable
– Step size — the difference between sequential value of the loop variable
759. What do the three expression in C’s for loop represent?
– First expression: initialization
– Second expression: loop control test
– Third expression: Often used to increment loop counter since it’s evaluated after each execution of the loop body
760. True or False? In C, the comma operator can be used to join multiple expressions into a single expression.
– True
761. True or False? C’s for statements often have empty bodies since all the work can be done in the controlling expressions.
– True
762. True or False? C99 can have a declaration in its first expression.
– True
763. True or false? In pure functional languages, content counters are used for iteration.
– False. Do not contain counter variables and recursion is used instead of iteration
764. What does the reserved word rec indicate in F#’s function declaration?
– That the function is recursive
765. True or False? Every counting loop can be built with a logical loop, but the reverse is not true.
– True
766. Java’s while and do statements are like those of C and C++, except the control expression must have a ______ type.
– Boolean
767. How can pretest logical loops be simulated in a functional language?
– recursive function
768. In a loop, what is an example of an unlabeled exit?
– break
769. True or False? The exit statements in Java and Perl (i.e. break and last) can specify a label.
– True
770. What does the continue statement do in a loop?
– Skips the rest of the loop body
771. In iteration based data structures, an iterative statement uses an _______ to traverse the elements of a data structure.
– iterator
772. True or False? In PHP, each array contains an internal pointer to its “current” element.
– True
773. What does the current function return in PHP?
– the element that is currently being pointed to by the internal pointer
774. What is Java’s solution to iteration over elements in an array?
– enhanced for loop
775. In C#, the iterator can be accessed through the _______ statement.
– foreach
776. True or False? C# users can define their own collections and write their own iterators.
– True
777. In Ruby, a _____ is a sequence of code delimited by either braces or the do and end reserved words.
– block
778. Is the following code valid in Ruby and does it produce the result displayed?
>> 4.times {puts “Hey!”}
Hey!
Hey!
Hey!
Hey!
=> 4
– It’s valid and does produce the results displayed
779. Provide an example of using the each statement in Ruby.
>> list = [2, 4, 6, 8]
=> [2, 4, 6, 8]
>> list.each {|value| puts value}
2
4
6
8
=> [2, 4, 6, 8]
780. Instead of a counting loop, Ruby has the _____ method.
– upto
i.e.
>> 1.upto(5) {|x| print x, “ “}
1 2 3 4 5
781. True or False? An unconditional branch statement, or goto, transfers control to a specified location in a program.
– True
Want more?
P1. 104 Programming Language Q&A
P2. 95 Programming Language Q&A
P3. 123 Programming Language Q&A
P4. 77 Programming Language Q&A
P5. 146 Programming Language Q&A
P6. 94 Programming Language Q&A
P7. 141 Programming Language Q&A