Posted on

C Examples

C++ Example Programs


C Tutorial -Examples

Add Numbers (Folder)

Armstrong_Numbers

  • Armstrong_Numbers.c

Ascending_Descending_Order

Binary_to_Decimal (Folder)

Binary_to_Hexadecimal (Folder)

Bubble_sort_Algorithm (Folder)

Decimal_to_Binary

Decimal_to_Hexadecimal

Factorial

——————————————–

Fibonacci-Series

Fibonacci_Series.c

————————————————–

Floyd’s_Triangle

Floyd’s_Triangle.c

——————————————————————

Pyramid(Folder)

  •  https://cprogrammingcodes.blogspot.in/p/pyramid.html
  • Generate a following structure : GitHub code Square_Structure.c

@@@@@

@@@@@

@@@@@

@@@@@

@@@@@

#####

  ####

    ###

      ##

        #

————————————————————————-

Greatest_Common_Divisor

——————————————————- 

Largest and Smallest number (Folder)

Odd or Even (Folder)

———————————————–

Prime_Number

 —————————————————-

Random_Number_Generator (Folder)

—————————————————-

Reverse_Number_and_Palindrome_Checker

————————————

Simple and Compound Interest

  • Simple_and_Compound_Interest.c

————————————

Swapping

Swapping Strings (Folder)

Windows Commands

If you want to access the windows commands using C program? its very easy to do. For that you need to include predecessor (stdlib.h) . See the Below code

******************************************

Posted on

C Quiz-1

http://www.pskills.org/randomtest.jsp?test=crandomtest

Ques 1 : Can a program be invoked from another program ?

(A) True

(B) False

Ans :(A) True (a program can invoke another program using system calls.)


Ques 2 :

What will be printed as the result of the operation below:

(A) system

(B) error

(C) Cisco

(D) Compilation fail

Ans :(B) Error


Ques 3 :How many times main()  will get called?

(A) 1

(B) 100

(C) main can not be called recursively

(D) Infinite

Ans :(D) Infinite (There is no condition in the main() to stop the recursive calling of the  main()  hence it will be called infinite no of times.)


Ques 4 :

How many times the while loop will get executed?

(A) 100

(B) 1

(C) 0

(D) Infinite

Ans  : (D)Infinite


Ques 5 : What is the output of the following program?

(A) 2

(B) 3

(C) 4

(D) 5

Ans: (D) 5


Ques 6 : What is the output of following program?

(A) 10

(B) 11

(C) 12

(D) 13

Ans: (A) 10


Ques 7 :

11 ^ 5

What does the operation shown above produce?

(A) 1

(B) 6

(C) 8

(D) 14

Ans :(D)14


Ques 8 :Suppose a,b,c are integer variables with values 5,6,7 respectively.  What is the value of the expression  : !((b+c)>(a+10)) 

(A) 1

(B) 6

(C) 15

(D) 0

Ans : (A) 1

Description :  1.!((b+c)>(a+10))

2.  !((6 + 7) > (5+10))

3.  !(13 > 15)   13 is less than 15 so it will return False (0 ).

4.   !(0).    Not of  0 is 1.


Ques 9 : How many variables scopes are there in “C” language?

(A) 2

(B) 3

(C) 4

(D) 5

Ans ; (C) 4 [body, function, program and file scope in “C”. ]


Ques 10 :What will be output of following program?

(A) 2

(B) 320

(C) 64

(D) Compilation Error

Answer : 64

Description : As we know int is two byte data byte while char is one byte data byte. Character pointer can keep the address one byte at time.

Binary value of 320 is 00000001 01000000 (In 16 bit) Memory representation of int a = 320 is:

So ptr is pointing only first 8 bit which color is  green and Decimal value is 64. 


Ques 11 :

What is the output of the following code?

(A) Skills 15

(B) Programing 5

(C) Programing 15

(D) Skills 5

Answer : Programing 15

Description : Condition is true come inside if part and print Programing 15.


Ques 12 : What is the output of following program?

(A) 4

(B) 5

(C) 6

(D) nothing display on screen

Answer : 5


Ques 13 :

What will be the output

(A) 5 11

(B) 6 10

(C) 6 11

(D) 5 10

Answer : 5 11

Description : Value in a function get passed from right to left. First i++ get passed and it make i = 11


Ques 14 : What is the output of following program?

(A) 11 12 12

(B) 11 12 13

(C) 12 12 12

(D) 12 12 13

Answer : 12 12 12


Ques 15 :

What will be output when you will execute following code?

(A) 5 25

(B) 25 15

(C) 25 5

(D) 25 40

Answer : 25 15


Ques 16 : what is the output of following program?


 

(A) 2 4 2 4

(B) 2 2 4 2

(C) 2 2 2 2

(D) 2 4 2 2


Ques 17 : What is the output of following program?

(A) 100 100 0000144 0x0064

(B) 100 100.00 0000144 0x0064

(C) 100 100 0000144 0x0032

(D) 100 100 0000127 0x0064

Answer : 100 100 0000144 0x0064


Ques 18 : What is the output of following program?

(A) A B C

(B) A B C E

(C) A B C D E

(D) error

Answer : error

Description : switch(a); 

terminated by ;


Ques 19 : What is the output of the following program?

(A) 43

(B) 64

(C) 31

(D) none of these

Answer : 31


Ques 20 : What is the output of following program?

(A) 1 1 2 1

(B) 1 2 1 1

(C) 1 2 2 1

(D) 1 2 1 2


Ques 2 : What is the output of the following program?

(A) 4 7

(B) 5 7

(C) 4 8

(D) 5 8

Ans : 4,6


Ques 3 : What is the output of the following program?

(A) 10 11 12 13 13

(B) 11 12 13 13 14

(C) 10 11 12 12 13

(D) 11 12 13 14 14

Ans (D);11 12 13 14 14


Ques 4 : What is the output of following program?

(A) 5 6

(B) 6 6

(C) 6 7

(D) 5 5

Answer : 6 7


Ques 5 :

What will be the output of  the following program

(A) 11 21 31 41

(B) 20 30 40 50

(C) 21 31 41 51

(D) 10 20 30 40

 Ans:(B) 20 30 40 50

Description :

When we call the function fun() the current address contained by it will get passed and then it get incremented. For ex. If the base address is of the array is 100 then successive elements are stored at 102, 104, 106 and 108.

In the first call 100 get passed to fun() and ptr becomes 102. Now the called function fun() manipulates the value stored at 100 and in the main() function values at the address contained by ptr are getting printed


Ques 6 :

Which one of the following functions is the correct choice for moving blocks of binary data that are of arbitrary size and position in memory?

(A) memset()

(B) memcpy()

(C) strncpy()

(D) memmove()

Answer : memmove()


Ques 7 : What is the output of following program?

(A) 1 2

(B) 2 3

(C) 1 3

(D) 3 1

Answer : 1 3


Ques 8 :

What will be output when you will execute following code?

(A) 249

(B) 250

(C) -6

(D) 0

Answer : -6

Turbo C++ 3.0: -6

char a = 250;

250 is beyond the range of signed char. Its corresponding cyclic value is: -6

So, a = -6

Consider on the expression:

expr= a+ !a + ~a + ++a;

Operator! , ~ and ++ have equal precedence. And it associative is right to left.

So, First ++ operator will perform the operation. So value a will -5

Now,

Expr = -5 + !-5 + ~-5 + -5

= -5 + !-5 + 4 – 5

= -5 + 0 + 4 -5

= -6


Ques 9 :

What will be the output of the following program?

(A) ntonic

(B) tonic

(C) ic

(D) nic


Ques 10 : How many storage class specifiers in “C” language?

(A) 3

(B) 4

(C) 5

(D) 6

Answer : 4

Description : auto, register, static and extern are the storage class specifiers in “C”.


Ques 11 : What is the output of following program?

(A) 2 2

(B) 2 4

(C) 2 6

(D) 2 8

Answer : 2 8


Ques 12 :

#define MAX_NUM 15

Referring to the sample above, what is MAX_NUM?

(A) MAX_NUM is a precompiler constant.

(B) MAX_NUM is a preprocessor macro.

(C) MAX_NUM is an integer variable.

(D) MAX_NUM is a linker constant.

Answer : MAX_NUM is a preprocessor macro.


Ques 13 :

What will be printed as the result of the operation below:

(A) 5 7 8 4

(B) 5 7 9 4

(C) 5 8 9 4

(D) 5 7 9 5

Answer : 5 7 9 4

Description : In the expression j = 2 * (i++) the value of i is used before incrementing and in expression k =2*(++i); will get incremented first and then used in the expression


Ques 14 : What is the output of the following program?

(A) 0

(B) 1

(C) error

(D) none of these

Answer : 0


Ques 15 : What is the output of the following code?

(A) a=0

(B) a=garbage value

(C) error

(D) none of these

Answer : a=0


Ques 16 : what is the output of following program?

(A) hello 81

(B) welcome 81

(C) hello 80

(D) welcome 80

Answer : hello 81


Ques 17 :

What will be output when you will execute following code?

(A) a=0 b=6

(B) a=5 b=0

(C) a=5 b=6

(D) none of these

Answer : a=5 b=6


Ques 18 : What is the output of the following program?

(A) 10 11 13 14 14

(B) 11 12 14 15 15

(C) 12 13 15 16 16

(D) 11 12 13 14 14

Answer : 12 13 15 16 16


Ques 19 :

What does y in the sample code above equal?

(A) -3

(B) 0

(C) 4

(D) 4 + sizeof( int )

Answer : 4


Ques 20 : What is the output of the following program?

(A) 0

(B) garbage

(C) error

(D) 23


Ques 1 : What is the output of the following code?

(A) a=0

(B) a=garbage value

(C) error

(D) none of these

Answer : error

Description : Linking undefined symbol.


Ques 2 : What is the output of the following program?

(A) 10 11 12 13 14 15 16

(B) 11 12 13 14 15 16 27

(C) 10 11 12 13 14 15 25

(D) 11 11 12 13 14 15 25

Answer : 11 12 13 14 15 16 27


Ques 3 : What is the output of following program?

(A) 1 1 0

(B) 1 0 1

(C) -1 0 0

(D) -1 -1 0

Answer : -1 -1 0


Ques 4 :

What value of c will get printed

 

(A) 23

(B) 22

(C) 30

(D) Compilation Error

Description : printf() will return no. of bytes it printed.

Expression becomes

      c = 2 + ++b; 

then value of b is incremented before addition.


Ques 5 : What will be output when you will execute following c  code?

Choose all that

(A) The African

(B) The

(C) Compilation

(D) None of the aboce

Answer : Compilation

Description : Size of any character array cannot be less than the number of characters in any string which it has assigned. Size of an array can be equal (excluding null character) or reater than but never less than


Ques 6 : What is the output of following program?

(A) 0 1 1 10

(B) 10 0 1 10

(C) 1 2 3 4

(D) 1 1 1 10

Answer : 1 1 1 10


Ques 7 : What is the output of following program?

(A) 7

(B) 8

(C) 89

(D) error

Answer : error

Description : error L value required


Ques 8 :

What will be output of following program?

 

(A) 5 6 5

(B) 6 7 5

(C) 7 7 5

(D) 6 6 5

Answer : 7 7 5


Ques 9 :

What will be the output of the following program?

(A) Compilation Error

(B) P

(C) i

(D) l

Answer : i

Description : Pskills is a constant string and character at index 4 will get printed.


Ques 10 : What is the output of following program?

(A) 1

(B) 2

(C) error

(D) none of these

Answer : 1


Ques 11 : Which of the following program structure/component/statement is not an example for implementation of modularization ?

(A) DLL

(B) Functions

(C) type casting

Answer : type casting

Description : Option c) type casting. DLL and Functions help in modularization of a program while typecasting just converts from one data type to another.


Ques 12 :

What will be output when you will execute following code?

(A) 35

(B) 45

(C) 55

(D) 65

Answer : 55


Ques 13 :

How many times the while loop will get executed?

(A) 100

(B) 1

(C) 0

(D) Infinite

Answer : Infinite

Description : Loop will execute infinite no of times because of the ; at the end while loop.


Ques 14 : What is the output of the following program?

(A) 4 7

(B) 5 7

(C) 4 8

(D) 5 8


Ques 15 :

What will be output of the following program?

(A) 10

(B) 30

(C) 30

(D) 0

Answer : 10


Ques 16 : What is the output of the following code?

(A) a=0 in fun a=0

(B) a=7 in fun a=7

(C) a=7 in fun a=0

(D) error

Answer : a=7 in fun a=7


Ques 17 : what is the output of following program?

(A) A

(B) B

(C) error

(D) nothing display on screen


Ques 18 : What is the output of following program?

(A) 6 6 6

(B) 6 7 7

(C) 6 7 6

(D) error

Answer : error

Description : s in out of scope in main()


Ques 19 : What is the output of the following code?

(A) 1 1 2 1 3 1 4 1

(B) 1 1 2 1 3 1 4 1 5 1

(C) 1 0 2 0 3 1 4 1 5 1

(D) 0 1 2 0 3 1 4 1 5 1

Answer : 1 1 2 1 3 1 4 1 5 1


Ques 20 : what is the output of following program?

(A) One Two Three

(B) Two Three Four

(C) One Two Four

(D) One Three Four

Answer : One Two Four


Ques 1 : what is the output of following program?

(A) 2,2.000000

(B) 2,2.00

(C) 2,2

(D) none of these

(A) 2,2.000000


Ques 2 :

What will be output when you will execute following code?

(A) -4

(B) -5

(C) 10

(D) 11

Answer : -4

Description : Turbo C++ 3.0: -4

Default value of enum constant X is zero and

Z = Y + 1 = 5 + 1 = 6

So, a + b â?? p

=0 + 6 -10 = -4


Ques 3 :

What will be output when you will execute following code?

(A) welcome 5

(B) welcome 15

(C) hello 5

(D) hello 15

Answer : welcome 15


Ques 4 : what is the output of following program?

(A) 40 85

(B) 0 85

(C) 100 85

(D) 100 100


Ques 5 : what is the output of following program?

(A) 101 101

(B) 101 102

(C) 102 100

(D) 102 101

Answer : 102 100


Ques 6 :

What will be printed as the result of the operation below:

(A) system

(B) error

(C) Cisco

(D) Compilation fail


Ques 7 : What is the output of following program?

(A) 5 6

(B) 6 6

(C) 6 7

(D) 5 5

Answer : 6 7


Ques 8 : what is the output of following program?

(A) 2,-2,-2,-2,5

(B) 2,2,-2,-2,5

(C) 2,-2,2,-2,5

(D) 2,2,-2,-2,0

Answer : 2,2,-2,-2,5


Ques 9 : What is the output of following program?

(A) 1 2 3 4 5 6 ……………….infinite

(B) 1 2 3 4 5 5 ……………….infinite

(C) 1 2 3 4 4 4 ……………….infinite

(D) 1 2 3 4 4 3 ……………….infinite

Answer : 1 2 3 4 4 4 ……………….infinite


Ques 10 :

Which of the following is integral data type?

(A) void

(B) char

(C) float

(D) double

Answer : char

Description : In c char is integral data type. It stores the ASCII value of any character constant.


Ques 11 : What is the output of the following program?

(A) 2 11

(B) 1 11

(C) 2 12

(D) 1 12

Answer : 1 12


Ques 12 : What is the output of the following code?

(A) a=0 in fun a=0

(B) a=7 in fun a=7

(C) a=7 in fun a=0

(D) error

Answer : a=7 in fun a=7


Ques 13 :

What will be output of following program?

(A) 2

(B) 64

(C) 320

(D) None of above

Answer : 64

Description :

As we know int is two byte data byte while char is one

byte data byte. Character pointer can keep the address

one byte at time.

Binary value of 320 is 00000001 01000000 (In 16 bit)

Memory representation of int a = 320 is:

So ptr is pointing only first 8 bit which color is

green and Decimal value is 64.


Ques 14 : What is the output of following program?

(A) 0

(B) 1

(C) garbage

(D) none of these

Answer : 1

‘a’-97

‘A’-65


Ques 15 : What is the output of the following program?

(A) 10 11 12 13 14 15 16

(B) 11 12 13 14 15 16 27

(C) 10 11 12 13 14 15 25

(D) 11 11 12 13 14 15 25

Answer : 11 12 13 14 15 16 27


Ques 16 :

What will be output of following program?

(A) 5 6 5

(B) 6 7 5

(C) 7 7 5

(D) 6 6 5

Answer : 7 7 5


Ques 17 : What is the output of following program?

(A) 11

(B) 12

(C) 13

(D) none of these

Answer : 12


Ques 18 : What is the output of following program?

(A) 4

(B) 5

(C) 6

(D) nothing display on screen

Answer : 5


Ques 19 :

What will be output when you will execute following code?

(A) 0

(B) 1

(C) -2

(D) 2

Answer : 1


Ques 20 : What is the output of the following program?

(A) 4 7

(B) 5 7

(C) 4 8

(D) 5 8

Answer : 5 8


Ques 1 :

What will be the output of the following program?

(A) G

(B) n

(C) t

(D) none of these

Answer : t


Ques 2 :

How many times the below loop will get executed?

(A) 1

(B) 10

(C) 11

(D) infinite loop

Answer : 10


Ques 3 :

What does y in the sample code above equal?

(A) -3

(B) 0

(C) 4

(D) 4 + sizeof( int )

Answer : 4


Ques 4 : What the below statement will print if a=10

printf("%d %d",a, !a++); 

(A) 11 0

(B) 10 10

(C) 10 0

(D) 0 10

Answer : 11 0

Description : Values in the function get passed from right to left. First !a++ get processed which pass zero as argument and make a equal to 11


Ques 5 : What is the output of following program?

(A) 0 1 1 10

(B) 10 0 1 10

(C) 1 2 3 4

(D) 1 1 1 10

Answer : 1 1 1 10


Ques 6 : what is the output of following program?

(A) 3

(B) -3

(C) 0

(D) error

Answer : -3


Ques 7 : What is the output of following program?

(A) 12

(B) 13

(C) 14

(D) nothing display on screen.

Answer : 14


Ques 8 : Which of the following program structure/component/statement is not an example for implementation of modularization ?

(A) DLL

(B) Functions

(C) type casting

Answer : type casting

Description : Option c) type casting. DLL and Functions help in modularization of a program while typecasting just converts from one data type to another.


Ques 9 :

11 ^ 5

What does the operation shown above produce?

(A) 1

(B) 6

(C) 8

(D) 14

Answer : 14


Ques 10 :

What the below statement will print if a=10 and b = 20?

printf("%d",a==b);

(A) 20

(B) 10

(C) 1

(D) 0

Answer : 0

Description : a==b is a expression and will return 1 (true) or 0 (False) depending on the values of a and b. Here a and b are not equal so 0 is printed.


Ques 11 : What is the output of following program?

(A) 7

(B) 8

(C) 89

(D) error

Answer : error

Description : error L value required


Ques 12 :

What will be printed as the result of the operation below:

(A) system

(B) error

(C) Cisco

(D) Compilation fail


Ques 13 :

What will be the output of  the following program

(A) 11 21 31 41

(B) 20 30 40 50

(C) 21 31 41 51

(D) 10 20 30 40

Answer : 20 30 40 50

Description :

When we call the function fun() the current address contained by it will get passed and then it get incremented. For ex. If the base address is of the array is 100 then successive elements are stored at 102, 104, 106 and 108.

In the first call 100 get passed to fun() and ptr becomes 102. Now the called function fun() manipulates the value stored at 100 and in the main() function values at the address contained by ptr are getting printed.


Ques 14 : what is the output of following program?

(A) 2,2.000000

(B) 2,2.00

(C) 2,2

(D) none of these

Answer : 2,2.000000


Ques 15 :

What will be output when you will execute following code?

(A) C

(B) C++

(C) nothing display on screen

(D) none of these

Answer : C


Ques 16 : What is the output of following program?

(A) 0

(B) 1

(C) garbage

(D) none of these

Answer : 1


Ques 17 :

what will be the output when following code is executed

(A) 12,11,11,11

(B) 12,10,11,13

(C) 22,10,11,13

(D) 22,13,13,13

Answer : 22,13,13,13


Ques 18 : What will be the output

(A) True

(B) False

(C) Compilation Error

(D) Run time Error

Answer : False

Description : comma(,) operator returns the value which at the right hand side of , . if statement become if(0)


Ques 19 : What is the output of following program?

A) 2 2

(B) 2 4

(C) 2 6

(D) 2 8

Answer : 2 8


Ques 20 : What is the output of following program?

(A) 1

(B) 4

(C) 5

(D) 6

Answer : 5


Ques 1 : What is the output of following program?

(A) 1 12 1 12 1 13 0 14 10 24

(B) 1 11 1 11 1 13 0 14 10 24

(C) 1 11 1 12 1 13 0 14 10 24

(D) 1 11 1 12 1 14 0 14 10 24

Answer : 1 11 1 12 1 13 0 14 10 24


Ques 2 : what is the output of following program?

(A) 40 85

(B) 0 85

(C) 100 85

(D) 100 100

Answer : 100 85


Ques 3 : What is the output of following program?

Answer : error

Description : linking error undefined symbol – g


Ques 4 :

What will be output when you will execute following code?

(A) 11

(B) Garbage

(C) -2

(D) We cannot predict

Answer : We cannot predict

Description : Turbo C++ 3.0: We cannot predict

We cannot predict the value of volatile variable because its value can be changed by any microprocessor interrupt.


Ques 5 :

What will be output when you will execute following code?

(A) -4

(B) -5

(C) 10

(D) 11

Answer : -4

Description : Turbo C++ 3.0: -4

Default value of enum constant X is zero and

Z = Y + 1 = 5 + 1 = 6

So, a + b â?? p

=0 + 6 -10 = -4


Ques 6 : What is the output of following program?

(A) 11 11 13

(B) 13 11 11

(C) 11 12 13

(D) 13 12 11

Answer : 13 11 11


Ques 7 : What will be the output

(A) True

(B) False

(C) Syntax Error

(D) Run time Error

Answer : False

Description : In this  program we are comparing the addresses contained by ptr & ptr1 not the value at those addresses and pointers ptr and ptr1 have the addresses of different variables so above condition is false


Ques 8 :

what will be the output when following code is executed

(A) 12,11,11,11

(B) 12,10,11,13

(C) 22,10,11,13

(D) 22,13,13,13

Answer : 22,13,13,13


Ques 9 : What is the output of following program?

(A) 1

(B) 2

(C) error

(D) none of these

Answer : 1


Ques 10 : What will be the output

(A) True

(B) False

(C) Compilation Error

(D) Run time Error

Answer : False

Description : comma(,) operator returns the value which at the right hand side of , . if statement become if(0)


Ques 11 : How many times the below loop will get executed?

(A) 5

(B) 6

(C) Compilation Error

(D) Infinite

Answer : Infinite

Description : Above loop will iterate till i have non zero value. Initial value of i is 9 and it get decremented by 2 in every iteration ( 9, 7, 5, 3, 1, -1, -3 â?¦.).  Value of i will never become 0 and loop will run infinitely.


Ques 12 : What is the output of the following program?

(A) 10 11 12 13 14 15 16

(B) 11 12 13 14 15 16 27

(C) 10 11 12 13 14 15 25

(D) 11 11 12 13 14 15 25

Answer : 11 12 13 14 15 16 27


Ques 13 : What is the output of following program?

(A) 0 11

(B) 0 12

(C) 1 11

(D) 1 12

Answer : 1 12


Ques 14 : How many times the below loop will get executed?

(A) 1

(B) Run time Error

(C) 11

(D) Compilation Error

Answer : 11

Description : i will start from 10


Ques 15 : What is the output of following program?

(A) 1 2 3 4 13

(B) 1 2 3 3 14

(C) 1 2 3 3 13

(D) 1 2 3 4 14

Answer : 1 2 3 4 14

 


Ques 16 : What is the output of the following program?

(A) 3.5

(B) 3

(C) error

(D) garbage

Answer : error


Ques 17 : What will be output of the following c program?

 

(A) 5

(B) 10

(C) 15

(D) Compilation Error

Answer : 15

Description : Variable name can have only underscore


Ques 18 :

What will be printed as the result of the operation below:

(A) 5,10

(B) 10,5

(C) 0,5

(D) 10,0

Answer : 10,5


Ques 19 : What is the output of the following program?

(A) 100 200

(B) 200 300

(C) 300 200

(D) 100 200 300

Answer : 100 200


Ques 20 : What is the output of following program?

(A) 1 2

(B) 2 3

(C) 1 3

(D) 3 1

Answer : 1 3