Thursday, 28 March 2013

Quiz 1: The basics of C++


Tutorials - C++ Programming Quiz Solutions

1. What is the correct value to return to the operating system upon the successful completion of a program?
A. -1
B. 1
C. 0 
D. Programs do not return a value.

2. What is the only function all C++ programs must contain?
A. start()
B. system()
C. main() 
D. program()

3. What punctuation is used to signal the beginning and end of code blocks?

A. { }

B. -> and C. BEGIN and END
D. ( and )

4. What punctuation ends most lines of C++ code?
A. .
B. ;
C. :
D. '

5. Which of the following is a correct comment?
A. */ Comments */
B. ** Comment **
C. /* Comment */
D. { Comment }

6. Which of the following is not a correct variable type?
A. float
B. real
C. int
D. double

7. Which of the following is the correct operator to compare two variables?
A. :=
B. =
C. equal
D. ==

Blog Author: Vijay Kumar


Wednesday, 27 March 2013

What is difference between uninitialized pointer and null pointer?


What is difference between uninitialized pointer and null pointer?  
Explanation:
An uninitialized pointer is a pointer which points unknown memory location while null pointer is pointer which points a null value or base address of segment. For example: 

int *p;   //Uninitialized pointer
int *q= (int *)0;  //Null pointer
#include<stdio.h>
int *r=NULL;   //Null pointer

What will be output of following c program?

#include<string.h>
#include<stdio.h>
int main(){
    char *p;  //Uninitialized pointer
    char *q=NULL;   //Null pointer;
    strcpy(p,"cquestion");
    strcpy(q,"cquestion");
    
    printf("%s  %s",p,q);
    return 0;
}

Output: cquestion (null)

Blog Author: Vijay Kumar