Posts

Showing posts with the label C

Interview Questions on Fundamental of C Language set-8

1) The control automatically passes the first statement after the loop in .. A. Continue statement B. Break statement C. Switch statement D. If statement 2) Which of the following is a scalar data type? A. Float B. Union C. Array D. Pointer 3) The given FOR loop is .. for( ; ; ) { printf(" "); } A. valid B. invalid C. indefinite D. displays runtime error 4) In C, a union is ...... A. memory location B. memory store C. memory screen D. memory space 5) The ......... statement causes immediate exit from the loop overriding the condition test .. A. Exit B. Break C. Goto D. None of the above 6) Pointers are of .......... A. integer data type B. character data type C. unsigned integer data type D. None of these 7) The keyword used to transfer control from a function back to the calling function is ... A. switch B. goto C. go back D. return 8) Identify the invalid pointer arithmetic ...... A. addition of float value to a pointer B. comparison of pointers that do not point to the...

Solved MCQ on Fundamental of C Language set-7

1) 'C' allows a three way transfer of control with the help of A. Unary Operator B. Relational Operator C. Ternary Operator D. Comparison Operator 2) Operators have hierarchy. It is used to know which operator .... A. is most important B. is used first C. is faster D. operators on large numbers 3) The statement that transfers control to the beginning of the loop is called .. A. break statement B. exit statement C. continue statement D. goto statement 4) C programming language was developed by .. A. Dennis Ritche B. Ken Thompson C. Bill Gates D. Peter Norton 5) The value that follows the keyword CASE may only be A. constants B. variable C. number D. semicolon 6) In a C language 'a' represents ... A. a digit B. an integer C. a character D. a word 7) The statement which is used to terminate the control from the loop is A. break B. continue C. goto D. exit 8) The continue command cannot be used with .... A. for B. switch C. do D. while 9) A self contained block of statement...

Solved MCQ on C Programming Language set-5

1. What will be output of the following C program? #include int main() {int goto=5; printf("%d",goto); return 0;} A) 5 B) 10 C) ** D) compilation error 2. Output of the following C program fragment is. x=5; y=x++; printf("%d %d", x,y); A) 5, 6 B) 5, 5 C) 6, 5 D) 6, 6 3. What will be output of the following C program? #include int xyz=10; int main() { int xyz=20; printf("%d", xyz); return 0;} A) 10 B) 20 C) 30 D) compilation error 4. Following program fragment. main(){ printf("%p\n", main( ) ); } A) Prints the address of main function B) Prints 0 C) Is an error D) In an infinite loop 5. What will be output of the following program? #include int main() {int a=2, b=7, c=10; c=a==b; printf("%d",c); return 0;} A) 0 B) 7 C) 10 D) 2 6. What is the output of the following program segment? main( ) { long i=65536; printf("%d\n", i); } A) 0 B) 65536 C) -1 D) 65 7. What will be the output of the program? # include int main() {int ...

MCQ on C Programming With Answers set-4

1. 'C' is often called a .... A) Object oriented language B) High level language C) Assembly language D) Machine level language 2. Each C preprocessor directive begins with .... A) # B) include C) main() D) { 3. C allows arrays of greater than two dimensions, who will determine this? A) programmer B) compiler C) parameter D) None of the above 4. The << operator is used for A) Right shifting B) Left shifting C) Bitwise shifting D) Bitwise complement 5. Set of values of the same type, which have a single name followed by an index is called A) function B) structure C) array D) union 6. Which of the following header file is required for strcpy() function? A) String.h B) Strings.h C) file.h D) strcpy() 7. scanf() can be used for reading ... A) double character B) single character C) multiple characters D) no character 8. A variable which is visible only in the function in which it is defined is called A) Static variable B) auto variable C) external variable D) local variable ...

Write a Program in C to Find if a Number is Present in a List or not

Image
Here is a C program to find if a number is present in a list of N numbers or not. In this program for loop is used to search a number from the list of numbers and array of numbers is used to insert numbers in a list. If the searched number is matched with any number in the list it throws to print it is presented in the list and if the searched number is not matched with any number in the list it throws to print it is not presented in the list.  A C Program to Find if a Number is Present in a List of N numbers or not Steps:   At first declare integers i, n, m, and array of integers a[10]. Print the message to enter how many elements want to insert and allow to insert. Print the message to enter the elements in the array. Use for loop to find out whether the given number is present in the list or not. Print the message on the screen whether the given number is present in the list or not. Code: #include<stdio.h> #include<conio.h> void main() { int i,n,m,flag=0; int ...

C Program to Find the Sum and Average of Numbers Using Do-While Loop

Image
In this program sum and average of of the given numbers are calculated using do-while loop. Do-while loop is a looping condition where statements are executed continuously until the condition validates and test the condition after having executed the statements within the loop. This means that do-while would execute its statements at least once, even if the condition fails for the first time.   Scanf() command is used here to allow enter the numbers and sum=sum+num; to sum the numbers within do-while loop. C Program to Find the Sum and Average of Numbers Using Do-While Loop Steps:    Declare two integers i and n and also initialize i with 0. Declare three floats sum, avg and num and initialize sum with 0. Print the message on the screen to enter how many numbers want to find sum. Use do-while loop to insert the numbers calculate the sum and average. Code: #include<stdio.h> #include<conio.h> void main() { int i=0,n; float sum, avg, num; clrscr(); sum=0; pr...

Write a Program in C to Sort a List of Numbers in Ascending Order

Image
In the program below nested  for loop is used to sort a list of  real numbers in ascending order. This program below asks to enter how many numbers want to sort and allow to enter the numbers to sort them in ascending order. The nested for loop in the program swaps the numbers if first number is greater than the next number. i.e. using (a[j]>a[j+1]) and        c=a[j];        a[j]=a[j+1];        a[j+1]=c; Here the value of a[j] copied to c and value of a[j+1] copied to a[j] and then value of c is copied to a[j+1].  Program in C to Sort a List of Numbers in Ascending Order Steps: Declare an array with float to insert real numbers. Declare integers i, j, n, c and flag. Print the message to enter how many numbers want to insert and allow to enter the number.  Use for() loop to allow to enter the numbers to sort in ascending order. Use nested for() loop to to sort the list. Again use for()...

Write a Program in C to Calculate the Factorial Value of an Integer.

Image
Here is a program in C to calculate the factorial value of an integer. The factorial of a number is the product of all the integers between 1 and that number.  For example factorial of 5 is 5*4*3*2*1. This can also be expressed as 5!=5*4!, where '!' stands for factorial. Hence factorial of a number can also be programmed using recursion. Here I have given two methods for calculating factorial of a number, using non-recursive function and using recursive function. Non-recursive function for calculating the factorial value of an integer   Steps: Declare prototype for the function named factorial() used to calculate factorial value. Declare two integers a and fact. Prompt the message to enter any number to calculate the factorial. Allow the user to enter number using scanf(). Use function factorial() to calculate the factorial value and return that. Print the returned value to the screen using printf() command.    code: #include <stdio.h> int factorial(int); int ...

Write a Program in C to Copy a String to Another.

Image
Here is a program in C to copy one string to another string using user defined function. Here two character arrays are defined then prompted to enter the strings and copied to the first string using while() function. Program in C to Copy a String to Another Steps: At first  declare two strings str1 and str2 and integers m , i , flag and j under main function. Prompt message to enter the strings and allow to enter strings using gets() function. Prompt the message and allow to enter the index where you want to insert in the first string. Copy second string to the first string using while() function. Print the first string to the screen. Code: #include <stdio.h> #include <conio.h> void main() { char str1[20], str2[20]; int m,i,flag=0,j; clrscr(); printf("Enter the 1st String"); gets(str1); printf("Enter the 2nd String"); gets(str2); printf("Enter the index after which you want to insert 2nd string in 1st :"); scanf("%d",...

C Program to Read Set of Real Numbers from Keyboard & Find the Maximum

Image
To write a C program to read set of real numbers from keyboard and find the maximum among them, you can use a function which takes an array of real numbers and its size as arguments and return the maximum. Using this function you can write a program to read a set of real numbers from the keyboard and find the maximum number in the array. C Program to Read Set of Real Numbers and Find the Maximum Steps:  Define a function max()  Under main() function, declare two integers i and n . Declare an array a. Prompt the message to the user to insert how many elements they want to enter using printf() and allow to enter using scanf(). Prompt the message and allow to enter the elements. Find out the maximum number among them using max() function. Print the maximum number along with message. Code: #include<stdio.h> #include<conio.h> max(float a[], int n); void main() { int i,n; float a[100]; printf("\n How many elements you want to enter:\n"); scanf("%d",...

Write a Program in C to Determine Whether a Number is Prime or Not.

Image
"A prime number is one, which is divisible only by 1 or itself." To determine whether a number is prime or not, we have to divide the number successively by all numbers from 2 to one less than itself. If remainder of any of these divisions is zero, the number is not a prime. If no division yields a zero then the number is a prime number. Program in C to Determine Whether a Number is Prime or Not Steps: Declare integers num and i inside main() Prompt the message allow the input using printf() and scanf() Test whether a Number is prime or not using while() function. Code: #include <stdio.h> int main() { int num, i; printf("Enter a number"); scanf ("%d",&num); i=2; while (i<=num-1) { if (num%i==0) { printf("Not a prime number\n"); break; } i++; } if (i==num) printf("Prime number\n"); return 0; } Related Posts:  How to Create Simple JavaScript Fade Effect Animation? Image Slideshow with Navigation Button...

Solved MCQ of Programming in C set-3

Image
Dependency graph for tgmath.h header file in C Programming Language (Photo credit: Wikipedia ) 1. C language is available for which of the following operating systems? A) DOS B) Windows C) Unix D) All of the above 2. Which of the following are tokens in C? A) Keywords B) Variables C) Constraints D) All of the above 3. C was developed in the year ..................... A) 1970 B) 1972 C) 1976 D) 1980 4. Which escape character can be used to beep from speaker in C? A) \a B) \b C) \m D) \n 5. Which of the following is a keyword is used for storage class? A) printf B) external C) auto D) scanf 6. Continue statement is used ............. A) to go to the next iteration in a loop B) come out of a loop C) exit and return to the main function D) restarts iteration from beginning of loop 7. File manipulation functions in C are available in which header file ? A) streams.h B) stdio.h C) stdlib.h D) files.h 8. A compiler ................ A) is a computer program B) translates a high level languag...

Objective Questions of C with answer set-2

1. Hierarchy decides which operator A) is most important B) is used first C) is fastest D) Operates on largest numbers 2. A pointer can hold A) Single address at a time B) Two addresses at a time C) Number of addresses at a time D) No address 3. An integer constant in C must have A) At least one digit B) At least one decimal point C) A comma along with digits D) Digits separated by commas 4. main() {                 Int a=3, b=2, c*d*e;                 d=&a; e=&b;                 c=*d+*e;                 }                 Which one of the given answers is correct? A) a=4, c-6 B) a=3, c=5 C) a=3, c=6 D) a=3, c=8...

Solved MCQ of C set-1

1. C language has been developed by A) Martin Richards B) Bijarne Stroustrup C) Dennis Ritche D) Ken Thompson 2. int[ ] ={5,6,7,8,9} What is the value of a[3]? A) 9 B) 8 C) 7 D) 6 3. C can be used on A) Only MS-Dos operating System B) Only Linux operating system C) Only Windows operating system D) All of the above 4. Float a[15], what is the size of array? A) 17 B) 14 C) 15 D) 16 5. C programs are converted into machine language with the help of A) An Editor B) A complier C) An operating system D) None of the above 6. Array is A) Primary data type B) Pointer data type C) Heterogeneous data type D) Homogenous data type 7. Which of the following is allowed in a C Arithmetic Instruction? A) [ ] B) { } C) ( ) D) None of the above 8. To accept 100 different values into the array we require A) Loop B) If condition C) Function D) Structure 9. If a is an integer variable, a=7/3; will return a value A) 2.5 B) 3 C) 0 D) 2 10. Pointer holds A) Value of variable B) Address of variable C) Value and...