C Language

Description: programming tricks and concept based problems..
Number of Questions: 14
Created by:
Tags: programming and theory Compiler Design Java/Oracle /C/C++ Programming - C / C++ Programming and Data Structures Pointer Array
Attempted 0/14 Correct 0 Score 0

There are some rules for declaring a variable in C language. Which of the following rules is/are not correct for declaring variables?

  1. The variable name cannot start with a digit.

  2. The variables cannot be a C keyword.

  3. They must begin with a character without spaces but underscore is not permitted.

  4. Both 1 and 3.

  5. None of these


Correct Option: C
Explanation:

Yes, this is true that variable name must start with a character. But we are allowed to put underscore. For example, Int ab_c; is a valid variable in C. So, this rule is not correct.

Which of the following conversion symbols used in printf statements in C language is/are invalid?

  1. %p

  2. %g

  3. %o

  4. None of these

  5. All of the above


Correct Option: D
Explanation:

None of the conversion symbols are invalid. So, this is the correct answer.

How many keywords are there in ANSI C?

  1. 32

  2. 33

  3. 34

  4. 35

  5. 36


Correct Option: A
Explanation:

There are 32 standard keywords in ANSI C. These are auto, double, int, struct, break, else, long, switch, case, enum, register, typedef, char, extern, return, union, const, float, short, unsigned, continue, for, signed, void, default, sizeof, goto, volatile, do, if, static and while. These are 32, so this option is true.

Which of the following statements is/are true?

  1. Long integer occupies 4 bytes in the memory and its range is - 2147483648 to + 2147483647.

  2. Unsigned integer occupies 2 bytes in the memory and its range is 0 to 65535.

  3. Double occupies 8 bytes in the memory and its range is 1.7e - 308 to 1.7e + 308.

  4. Only 1 and 3.

  5. All of the above.


Correct Option: E
Explanation:

All of the given statements are true. So, this is the correct option.

#include<stdio.h> #include<conio.h> int main() { int a=9,b=10,c; c=(b<a || b>a); printf(c=%d,c); getch(); }

Find the output of the above program or error, if any.

  1. c=1

  2. c=0

  3. c=-1

  4. garbage value

  5. error in the program


Correct Option: A
Explanation:

This program will first compare a > b, which is false as 9 < 10. So result will be 0. Then it will compare b > a (10 > 9) which is true. So result will be 1.So it will become as c=(0 || 1). So binary of 0 OR binary of 1. The result will be 1 0 0 0 0 0 1____0 0 1. So, this is the correct answer.

If x = 9.3, y = x - 5.1, z = x - 0.2, k = y + 1.5, a = k + 2.2, b = a - 1.6, h = z + 2.8, u = 625 / 25 and t = 7, then solve the following expression according to the precedence. P = (x - y + z / k - a / b - h + u % t).

  1. P = - 2.54768

  2. P = - 2.45748

  3. P = - 2.54678

  4. P = - 2.54878

  5. P = - 2.45768


Correct Option: B
Explanation:

This option is correct. First z / k will be solved which comes out to be 1.59649. Then a / b will be solved which comes out to be 1.25397. Then u % t will be solved which comes out to be 4. So, the last expression will be: 5.1 + 1.59649 - 1.25397 - 11.9 + 4. Solving it, the result will be -2.45748.

#include<stdio.h> #include<coni.h> int main() { unsigned long v=-1; printf(v=%lu,v); getch(); }

Find the output of the above program or error, if any.

  1. v=-1

  2. v=4294967295

  3. v=4294967296

  4. v=0

  5. error in the program


Correct Option: B
Explanation:

Unsigned data types don’t have negative values. They have range from 0 to 4294967295. So, if negative value is given to any variable, it will count from its last value,  which is 4294967295. So, this is the correct answer. If we give v = -2, the result will be 4294967294. So, it will keep decrementing values.

C language has some special characters. Which of the following special characters is invalid?

  1. : (colon)

  2. ; (semicolon)

  3. (hash)

  4. , (comma)

  5. none of these


Correct Option: E
Explanation:

According to the reason explained, all the options are true. There is no invalid special character. So, this is the correct option.

What will be the value of c after the execution of the following program? #include<stdio.h> #include<conio.h> int main() { int c=1,d=0; while(d<=9) { printf( %d%d,++d,++c); } getch(); }

  1. 9

  2. 10

  3. 11

  4. 12

  5. None of these


Correct Option: C
Explanation:

This program will run until d becomes greater than 9. As we can see the value of c (c=1) is greater than d (d=0). So c will always be one greater than the value of d, because both are incrementing at the same time. So, when d = 0 (d <= 9), condition becomes true. So when d becomes 1, c becomes 2, and when d is 9 (d <= 9), which is again true, then d becomes 10 and c becomes 11, which is one greater than d. The program runs 10 times. So final value of c is 11.

Which of the following statements is correct for the given program? #include<stdio.h> #include<conio.h> int main() { int a1,a2,c=3,pt; pt=&c; a1=3(c+5); a2=3*(*pt+5); printf(a1=%d,a2=%d,a1,a2); getch(); }

  1. a=24, b=24

  2. a=12, b=24

  3. We cannot perform addition in pointers(*pt+5)

  4. None of these

  5. Error in the program


Correct Option: A
Explanation:

First the value of c=3 is assigned to pt by the statement pt=&c. So in a1=3(c+5), it becomes a1=3*(3+5). So result is a1=24. After that we know that pt is equal to the value of c,  which is 3. So, a2=3(pt+5) becomes a2=3(3+5). The result is again 24. So, both ai and a2 are 24. Therefore, this is the correct option.

What will be the output of the given program? #include<stdio.h> #include<conio.h> int main() { char x='G'; switch(x) { if(x=='B') { case 'd': printf(%c,'o'); case 'B': printf(%s,Bad); } else { case 'G': printf(%s,Good); default: printf(%s,Boy); } } getch(); }

  1. GoodBoy

  2. Good

  3. Boy

  4. None of these

  5. Error in the program


Correct Option: A
Explanation:

The program will switch the statements with the value x=’G’. If (x==’B’), then if part will be executed. But x is equal to ‘G’. So, else part will be executed. Now the question arises that why default is executed. As we can see that else part contains the default part. Therefore, default is also executed with case ‘G’. So, the result is GoodBoy.

The C programs are converted into machine language using a/an ____________.

  1. assembler

  2. compiler

  3. interpreter

  4. operating system

  5. both 2 and 3


Correct Option: B
Explanation:

A compiler reads the entire program and converts it to the object code. It provides error, not of one line but error of the entire program. It takes more time for converting the lengthy programs. So this option is correct.

Find out the values of variables a and b after the execution of program or find out the error if any. #include<stdio.h> #include<conio.h> int main() { int a,b=&a,c=&b; a=5; **c=15; *b=*c; printf(a=%d,b=%d,a,*b); getch(); }

  1. a=5, b=15

  2. a=15, b=15

  3. a=5, b=5

  4. a=15, b=5

  5. Error in the program


Correct Option: B
Explanation:

In this program first we assign the value of a to b by the statement (b=&a), which means b contains value of a. Now after that **c contains the value of b (c=&b), which means value of b is in **c. Now we assign **c=15, which means **c=15 and b is also become 15 as (c=&b). Now as (*b=*c), it makes b=15. Now as we know (*b=&a), so value of a also becomes 15. In this way both a and b will be printed as 15.

Find out the output of the given program or find the error if any. #include<stdio.h> #include<conio.h> int main() { int s=25,d; d=s%10; if(d==5) { s=s/10; printf( result is=%d%d,s*s++,d*d); } else { printf( invalid number); } getch(); }

  1. Invalid number

  2. Result is 425

  3. Result is 625

  4. Result is 525

  5. Error in the program


Correct Option: C
Explanation:

The answer would be 425. The program will firstly find 25%10 which comes out to be 5. So if(d==5) becomes true, then 25/10=2 will be stored in s. And s*s++ will give the result 6 and d*d gives the result 25. So, 625 will get printed.

- Hide questions