C Programming Fundamentals
Test your knowledge of C programming language concepts including operators, control flow, arrays, functions, preprocessor directives, and recursion.
Questions
Which is the actual syntax to find the ratio of boys and girls in C language? (given that float ratio; int boys, girls;)
- ratio = boys/girls;
- ratio = girls/boys;
- ratio = (float) girls/boys;
- ratio = (float) boys/girls;
- ratio = float boys/girls;
Find the output of the following code in C language assuming other parameters are correct.
void main( )
{
int a; int b;
scanf ("%2d %5d", &a, &b);
printf ("a = %d and b=%d.",a,b);
}
/* input by the user is a=12345 and b = 67 during program execution*/
- a=12345 and b=67
- a=67 and b=12345
- a=12 and b=345
- a=12 and b=34567
- a=12 and b=67
Which one of the following is example of compound assignment operator in C language?
- a* = 5;
- a=a+5;
- a=a*5;
- a<5;
- a&&5
What will be output of the code if all other terms are assumed correct in C language?
int age=17;
(age>=18)?
printf( I can vote.) :
printf( I cannot vote.);
- Incorrect code
- Incorrect operator used
- I can vote
- I cannot vote
- No output
'goto' statement is used in C programming to __________.
- jump the control to specific location o screen
- hold the control for user input
- end the program execution
- restart the execution from beginning
- jump the control up or down at its label
What is the right coding to find the formatted output of float value upto 4 decimal points?
float a=23.76548;
- printf ( "% f ",a);
- printf ( "% 4" , a );
- printf ( "%2.4" f ;a);
- printf ( "% i" ,a);
- printf ( "%d" ;a);
Which of the following is not correct in context to array in C language?
- It is a group of variables of similar datatype.
- It stores the data in consucative memory location.
- It is referred by a common name.
- int val[5].
- Array size can be changed during program execution.
Write the steps to interchange the variable values using least memory usages. Given that - int i, j;
- swap(i,j);
- i=j; j=i;
- i = i + j ;j = i - j ;i = i - j ;
- j = i - j;i = i + j ;i = i + j ;
- int temp;temp=i;i = j;j = temp;
Which of the following statements is not correct about a function?
- It is a set of instructions.
- It performs a specific task.
- It is reusable.
- It is modular programming.
- None of these
Find the output of the following code in C language, if assumed that all preprocessor directives are correct.
void main ( )
{
int a = 2, b = 2;
if (a > 2)
if (b > 2)
printf ( "Hello");
Else
Printf ("Hi");
}
- Hello
- Hi
- Error in execution
- Normal program execution without any output
- Program code error
If class name is Y, which is the right code to declare the copy constructor of the class?
- Y(const Y & arg )
- Y(Const *Y arg )
- Y(Y arg)
- Y(Y & arg)
- None of these
A user defined header file myheader.h is saved at root directory. Write pre-processor directives to include the header file in the program code in C language.
- # include <myheader.h><myheader.h></myheader.h>
- include <myheader.h><myheader.h></myheader.h>
- # include C:myheader.h
- # include "C:myheader.h"
- main (C:myheader.h)
Which of the following is true?
- # define P printf
- define P printf
- # use P printf
- # <define p="printf="></define>
- # include
Which is correct statement about recursion?
- It is a function which calls to itself.
- It is a process in which a function calls to itself.
- It runs for definite number of time without condition.
- It is used to call global function.
- It is used to call local function.
Given code is written in C language. Find the output of the program.
int i = 6, j = 14, k = 7, l = 7, x;
x = i > j ? j > k ? 12 : k > l? 13 : 14 : 15;printf("%d", x);
- 12
- 13
- 14
- 15
- %d