What happens if the following C++ statement is compiled and executed?
int *ptr = NULL;delete ptr;
a) The program is not semantically correct
b) The program is compiled and executed successfully
c) The program gives a compile-time error
d) The program compiled successfully but throws an error during run-time
Answer: b
Explanation: The above statement is syntactically and semantically correct as C++ allows the programmer to delete a NULL pointer, therefore, the program is compiled and executed successfully.
(C++ concept on local variable) On page 14 of the “Pointers and
Memory” handout there is a reference to the “Amperand (&)” Bug
in the TAB() function. Draw a trace of the local variables of the
functions Victim() and TAB() on the run-time stack as these
functions are executed. Your diagram should be similar to the one
provided on page 13. Your diagram should depict exactly three
instances in program execution - T1: Right after the first
statement of Victim(),...
What happens when you try to compile and run the following code? String query = "INSERT INTO Invoices (InvoiceDate InvoiceTotal) " + "VALUES ('2/10/01', '443.55')"; Statement statement = connection.createStatement(); statement.executeUpdate(query); a. A SQLException is thrown at runtime because the executeUpdate method can’t accept a String object. b. A SQLException is thrown at runtime because the SQL statement is coded incorrectly. c. An error occurs at compile time because the SQL statement is coded incorrectly. d. This code compiles and...
Java questions
QUESTION 8 Assume the following classes are each defined in their own java files and compile public class A public void display { System.out.println("A's display"); public class B extends A{ public void display { System.out.println("B's display"); public class C extends A public void display { System.out.println("C's display"); public class D { public static void main(String args) { 3: int i = ((int)(Moth.random(* 10)) if (i == 0) a = new BO: else if (i == 1) a =...
QUESTION 6 What is the output of following C code? struct numbers { int x = 2; int y = 3; } int main() { struct numbers nums; nums.x = 110; nums.y = 100; printf("%d\n%d", nums.x, nums.y); return 0; } A. Compile-time Error B. 110 100 C. 2 3 D. Run-time Error 2 points QUESTION 7 What is the output of following C code? typedef struct student { char *stud; }s1; int main() { s1 s; s.stud...
QUESTION 1 In order to print the members of structures in the array, what will be the contents of blanks in the printf statement of the code snippet given below? #include <stdio.h> struct virus { char signature[25]; char status[20]; } v[2] = { "Yankee Doodle", "Deadly", "Dark Avenger", "Killer" } ; void main( ) { for (int i = 0; i < 2; i++) printf( "\n%s %s", _______________ , _____________ ); } A. signature, status B. v.signature,...
Consider the following codes: public class TestThread extends Thread { public static void main(String[] args) { TestThread thread = new TestThread(); } @Override public void run() { printMyName(); } private void printMyName() { System.out.println("Thread is running"); } } Test Stem / Question Choices 1: What method should you invoke to start the thread TestThread? A: start() B: run() C: No. Thread will run automatically when executed. D: TestThread is not...
I've been at this for a while and I can't seem to
crack this.
5. Download and compile this C code. What happens? $include # include <stdio.h < t dlib . h> int main) int i; int t; srand (time (NULL)) for (i-1 ; i 5000; i++) allilrand / ap the txo array / for (i=0 ; ic#5000; i++) a2[i] = t; /Print the arrays / for (i=0 ; í例000; i++) free (a1); free (a2): Type the program and run...
What is the output of the following C program? int x=1, y=2; int * const ptr = &x; ptr = &y; printf("%d\n", *ptr); What is the output of the following C program? int x=1, y=2; const int * ptr = &x; ptr = &y; printf("%d\n", *ptr); What is the output of the following C program? int x=1, y=2; int * ptr = &x; ptr = &y; printf("%d\n", *ptr); What is the output of the following C program? int x=1, y=2;...
What is the output of this program? void wth(int i, int &k) { i = 1; k = 2; } int main (){ int x = 0; wth(x, x); cout << x << endl; return 0; } (a) 2 (b) wth (c) 1 (d) Run-time error (e) 0 (f) Compile-time error (g) None of the above
Starting New Processes We can create a new process from within another program using the system library function: #include <stdlib.h> int system ( const char *str ); The system function runs the command passed to it as str and waits for it to complete. The command is executed as if the command, $ sh -c str Use the "man" command to study both the "sh" and "system" command. i.e. Execute $ man sh $ man system For example, $ sh...