Solved MCQs on C Programming

DATA TYPES 1. Comment on the output of this C code? #include <stdio.h> int main ( ) { ...



DATA TYPES

1. Comment on the output of this C code?
  1.     #include <stdio.h>
  2.     int main()
  3.     {
  4.         int a[5] = {1, 2, 3, 4, 5};
  5.         int i;
  6.         for (i = 0; i < 5; i++)
  7.             if ((char)a[i] == '5')
  8.                 printf("%d\n", a[i]);
  9.             else
  10.                 printf("FAIL\n");
  11.     }
a) The compiler will flag an error
b) Program will compile and print the output 5
c) Program will compile and print the ASCII value of 5
d) Program will compile and print FAIL for 5 times
View Answer
Answer:d
Explanation:The ASCII value of 5 is 53, the char type-casted integral value 5 is 5 only.
Output:
$ cc pgm1.c
$ a.out
FAILED
FAILED
FAILED
FAILED
FAILED
2. The format identifier ‘%i’ is also used for _____ data type?
a) char
b) int
c) float
d) double
View Answer
Answer:b
Explanation:Both %d and %i can be used as a format identifier for int data type.
3. Which data type is most suitable for storing a number 65000 in a 32-bit system?
a) signed short
b) unsigned short
c) long
d) int
View Answer
Answer:b
Explanation:65000 comes in the range of short (16-bit) which occupies the least memory. Signed short ranges from -32768 to 32767 and hence we should use unsigned short.
4. Which of the following is a User-defined data type?
a) typedef int Boolean;
b) typedef enum {Mon, Tue, Wed, Thu, Fri} Workdays;
c) struct {char name[10], int age};
d) all of the mentioned
View Answer
Answer:d
Explanation:typedef and struct are used to define user-defined data types.
5. What is the size of an int data type?
a) 4 Bytes
b) 8 Bytes
c) Depends on the system/compiler
d) Cannot be determined
View Answer
Answer:c
Explanation:The size of the data types depend on the system.
6. What is the output of this C code?
  1.     #include  <stdio.h>
  2.     int main()
  3.     {
  4.        signed char chr;
  5.        chr = 128;
  6.        printf("%d\n", chr);
  7.        return 0;
  8.     }
a) 128
b) -128
c) Depends on the compiler
d) None of the mentioned
View Answer
Answer:b
Explanation:signed char will be a negative number.
Output:
$ cc pgm2.c
$ a.out
-128
7. Comment on the output of this C code?
  1.     #include  <stdio.h>
  2.     int main()
  3.     {
  4.         char c;
  5.         int i = 0;
  6.         FILE *file;
  7.         file = fopen("test.txt", "w+");
  8.         fprintf(file, "%c", 'a');
  9.         fprintf(file, "%c", -1);
  10.         fprintf(file, "%c", 'b');
  11.         fclose(file);
  12.         file = fopen("test.txt", "r");
  13.         while ((c = fgetc(file)) !=  -1)
  14.             printf("%c", c);
  15.         return 0;
  16.     }
a) a
b) Infinite loop
c) Depends on what fgetc returns
d) Depends on the compiler
View Answer
Answer:a
Explanation:None.
Output:
$ cc pgm3.c
$ a.out
a
8. What is short int in C programming?
a) Basic datatype of C
b) Qualifier
c) short is the qualifier and int is the basic datatype
d) All of the mentioned
View Answer
Answer:c
Explanation:None.
SET 2
1. Comment on the output of this C code?
  1.     #include <stdio.h>
  2.     int main()
  3.     {
  4.         float f1 = 0.1;
  5.         if (f1 == 0.1)
  6.             printf("equal\n");
  7.         else
  8.             printf("not equal\n");
  9.     }
a) equal
b) not equal
c) Output depends on compiler
d) None of the mentioned
View Answer
Answer:b
Explanation:0.1 by default is of type double which has different representation than float resulting in inequality even after conversion.
Output:
$ cc pgm4.c
$ a.out
not equal
2. Comment on the output of this C code?
  1.     #include <stdio.h>
  2.     int main()
  3.     {
  4.         float f1 = 0.1;
  5.         if (f1 == 0.1f)
  6.             printf("equal\n");
  7.         else
  8.             printf("not equal\n");
  9.     }
a) equal
b) not equal
c) Output depends on compiler
d) None of the mentioned
View Answer
Answer:a
Explanation:0.1f results in 0.1 to be stored in floating point representations.
Output:
$ cc pgm5.c
$ a.out
equal
3. What is the output of this C code (on a 32-bit machine)?
  1.     #include <stdio.h>
  2.     int main()
  3.     {
  4.         int x = 10000;
  5.         double y = 56;
  6.         int *p = &x;
  7.         double *q = &y;
  8.         printf("p and q are %d and %d", sizeof(p), sizeof(q));
  9.         return 0;
  10.     }
a) p and q are 4 and 4
b) p and q are 4 and 8
c) Compiler error
d) p and q are 2 and 8
View Answer
Answer:a
Explanation:Size of any type of pointer is 4 on a 32-bit machine.
Output:
$ cc pgm6.c
$ a.out
p and q are 4 and 4
4. Which is correct with respect to size of the datatypes?
a) char > int > float
b) int > char > float
c) char < int < double
d) double > char > int
View Answer
Answer:c
Explanation:char has lesser bytes than int and int has lesser bytes than double in any system
5. What is the output of the following C code(on a 64 bit machine)?
  1.     #include <stdio.h>
  2.     union Sti
  3.     {
  4.         int nu;
  5.         char m;
  6.     };
  7.     int main()
  8.     {
  9.         union Sti s;
  10.         printf("%d", sizeof(s));
  11.         return 0;
  12.     }
a) 8
b) 5
c) 9
d) 4
View Answer
Answer:d
Explanation:Since the size of a union is the size of its maximum datatype, here int is the largest hence 4.
Output:
$ cc pgm7.c
$ a.out
4
6. What is the output of this C code?
  1.     #include <stdio.h>
  2.     int main()
  3.     {
  4.         float x = 'a';
  5.         printf("%f", x);
  6.         return 0;
  7.     }
a) a
b) run time error
c) a.0000000
d) 97.000000
View Answer
Answer:d
Explanation:Since the ASCII value of a is 97, the same is assigned to the float variable and printed.
Output:
$ cc pgm8.c
$ a.out
97.000000
7. Which of the datatypes have size that is variable?
a) int
b) struct
c) float
d) double
View Answer
Answer:b
Explanation:Since the size of the structure depends on its fields, it has a variable size.


VARIABLES

1. C99 standard guarantees uniqueness of ____ characters for internal names.
a) 31
b) 63
c) 12
d) 14

Answer:b
Explanation:ISO C99 compiler may consider only first 63 characters for internal.

2. C99 standard guarantess uniqueness of _____ characters for external names.
a) 31
b) 6
c) 12
d) 14

Answer:a
Explanation:ISO C99 compiler may consider only first 31 characters for external
variables having 31 characters due to which it may not be unique.

3. Which of the following is not a valid variable name declaration?
a) int __a3;
b) int __3a;
c) int __A3;
d) None of the mentioned

Answer:d
Explanation:None.

4. Which of the following is not a valid variable name declaration?
a) int _a3;
b) int a_3;
c) int 3_a;
d) int _3a

Answer:c
Explanation:Variable name cannot start with a digit.

5. Variable names beginning with underscore is not encouraged. Why?
a) It is not standardized
b) To avoid conflicts since assemblers and loaders use such names
c) To avoid conflicts since library routines use such names
d) To avoid conflicts with environment variables of an operating system

Answer:c
Explanation:None.

6. All keywords in C are in
a) LowerCase letters
b) UpperCase letters
c) CamelCase letters
d) None

Answer:a
Explanation:None.

7. Variable name resolving (number of significant characters for uniqueness of variable) depends on
a) Compiler and linker implementations
b) Assemblers and loaders implementations
c) C language
d) None

Answer:a
Explanation:It depends on the standard to which compiler and linkers are adhering to.

8. Which of the following is not a valid C variable name?
a) int number;
b) float rate;
c) int variable_count;
d) int $main;

Answer:d
Explanation:Since only underscore and no other special character is allowed in a variable name, it results in an error.

9. Which of the following is true for variable names in C?
a) They can contain alphanumeric characters as well as special characters
b) It is not an error to declare a variable to be one of the keywords(like goto, static)
c) Variable names cannot start with a digit
d) Variable can be of any length

Answer:c
Explanation:According to the syntax for C variable name, it cannot start with a digit.

SET 2

1. Which is valid C expression?
a) int my_num = 100,000;
b) int my_num = 100000;
c) int my num = 1000;
d) int $my_num = 10000;


Answer:b
Explanation:space, comma and $ cannot be used in a variable name.

2. What is the output of this C code?

    #include <stdio.h>
    int main()
    {
        printf("Hello World! %d \n", x);
        return 0;
    }
a) Hello World! x;
b) Hello World! followed by a junk value
c) Compile time error
d) Hello World!


Answer:c
Explanation:It results in an error since x is used without declaring the variable x.
Output:
$ cc pgm1.c
pgm1.c: In function ‘main’:
pgm1.c:4: error: ‘x’ undeclared (first use in this function)
pgm1.c:4: error: (Each undeclared identifier is reported only once
pgm1.c:4: error: for each function it appears in.)

3. What is the output of this C code?

    #include <stdio.h>
    int main()
    {
        int y = 10000;
        int y = 34;
        printf("Hello World! %d\n", y);
        return 0;
    }
a) Compile time error
b) Hello World! 34
c) Hello World! 1000
d) Hello World! followed by a junk value

Answer:a
Explanation:Since y is already defined, redefining it results in an error.
Output:
$ cc pgm2.c
pgm2.c: In function ‘main’:
pgm2.c:5: error: redefinition of ‘y’
pgm2.c:4: note: previous definition of ‘y’ was here

4. Which of the following is not a valid variable name declaration?
a) float PI = 3.14;
b) double PI = 3.14;
c) int PI = 3.14;
d) #define PI 3.14

Answer:d
Explanation:#define PI 3.14 is a macro preprocessor, it is a textual substitution.

5. What will happen if the below program is executed?

    #include <stdio.h>
    int main()
    {
        int main = 3;
        printf("%d", main);
        return 0;
    }
a) It will cause a compile-time error
b) It will cause a run-time error
c) It will run without any error and prints 3
d) It will experience infinite looping


Answer:c
Explanation:A C program can have same function name and same variable name.
$ cc pgm3.c
$ a.out
3
6. What is the problem in following variable declaration?
float 3Bedroom-Hall-Kitchen?;
a) The variable name begins with an integer
b) The special character ‘-‘
c) The special character ‘?’
d) All of the mentioned


Answer:d
Explanation:A variable name cannot start with an integer, along with that the C compiler
interprets the ‘-‘ and ‘?’ as a minus operator and a question mark operator respectively.

7. Comment on the output of this C code?

    #include <stdio.h>
    int main()
    {
        int ThisIsVariableName = 12;
        int ThisIsVariablename = 14;
        printf("%d", ThisIsVariablename);
        return 0;
    }
a) The program will print 12
b) The program will print 14
c) The program will have a runtime error
d) The program will cause a compile-time error due to redeclaration

View Answer
Answer:b
Explanation:Variable names ThisIsVariablename and ThisIsVariableName are both distinct as C is case sensitive.
Output:
$ cc pgm4.c
$ a.out
14

8. Which of the following cannot be a variable name in C?
a) volatile
b) true
c) friend
d) export
View Answer

Answer: a
Explanation:volatile is C keyword.

---------------------------------------------------------------------------------------------------------------------

TECH$type=three$author=hide

Name

5G Technology,1,Abbreviations,2,Agent AI,1,Agentic Ai,1,AI in Education,1,AI in Healthcare,1,AI in surgery,1,AI Reasoning,1,Algorithm,1,Algorithms,4,android,2,Artemis Mission,1,Artificial Intelligence,5,Artificial Intelligence AI,2,Artificial Neural Networks,1,ASCI and UNI),1,Augmented Reality,1,Automata,3,Blockchain,1,Blockchain Technology,1,C Language,2,C Programming,1,c#,1,C++,2,C++ Programming,1,CakePhp,1,Carbon Neutrality,1,CCNA,1,Cellular Communication,1,Chatgpt,1,Cloud Computing,4,Compiler Construction,1,Compiler Construction Solved MCQs,1,Compiler Design,1,Computer,18,Computer Applications,1,Computer Architecture,3,Computer Arithmetics,1,Computer Basics,1,Computer Codes (BCD,1,Computer Fundamentals,5,Computer Graphics,4,Computer Networking,2,Computer Networks,4,Computer Organization,1,Computer Science,2,Computer Short Cut Keys,1,Computer Short Keys,1,CPU Sceduling,1,Cryptocurrency,1,CSS,1,CSS PMS,1,Current Trends and Technologies,1,Custom Hardware,1,Cyber Security,6,Cybercrimes,1,DALL-E,1,Data Communication,1,Data Privacy,1,Data structures,3,Database Management System,4,DBMS,4,Deadlock,1,DeepSeek,1,Digital Systems,1,Digital Systems Solved MCQs - Part 2,1,Discrete Mathematics,2,Discrete Structure,1,dot Net,1,EBCDIC,1,Edge Computing,2,English,1,Ethical AI and Bias,1,Ethics,1,Explainable AI (XAI),1,File System,1,Flowcharts,1,General Data Protection Regulation GDPR,1,General Knowledge,1,Generative AI,2,Gig Economy,1,Graphics Designing,1,Helping Materials,1,HTML,1,HTML 5,1,hybrid work model,1,Inference Optimization,1,Information Systems,1,Information Technology,1,Inpage,1,intelligence,1,Internet,1,Internet Basics,1,Internet of Things,1,Internet of things IOT,2,IT,1,JavaScript,1,jQuery,1,Language,11,Languages Processor,1,Languge,1,Li-Fi,1,Linux/Unix,2,Magento,1,Memory Management,1,Microprocessor,1,Microsoft PowerPoint,1,MidJourney,1,mindfulness apps,1,MS Access,1,MS DOS,1,MS Excel,1,MS Word,2,Multimodal AI,1,NASA,1,Number System,1,Object Oriented Programming (OOP),1,Object Oriented Programming(OOP),1,Operating System,9,Operating System Basics,1,oracle,2,Others,1,Pakistan,1,PCS,1,PHP,1,PMS,1,Process Management,2,Programming,3,Programming Languages,1,Python,2,python language,1,Quantitative Aptitude,2,Quantum Computing,2,R Programming,1,Ransomware,1,Robotic Process Automation RPA,1,Robotics,2,Ruby Language,1,search engine optimization,1,Semester III,2,seo,1,Sloved MCQs on Microsoft Power Point - updated,1,Software Engineering,3,Solved MCQs of MS Access - Updated,1,Solved MCQs on Computer Fundamentals,1,SpaceX Starship,1,SQL,1,System Analysis and Design,1,Theory of Computation,1,Trends and Technologies,1,Virtual Reality,1,web,1,web Fundamental,1,Web Technologies,2,Web3,1,WEB3 Technology,1,x8086,1,zoology,1,
ltr
item
COMPUTER SCIENCE SOLVED MCQS: Solved MCQs on C Programming
Solved MCQs on C Programming
https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhn3a87s02btTfomcvsZ9Md7J5ZSOq4PE3ClEWXgJBj3B8rHyN9zHh1lW_uqeimGG8T-zoLP_evbKr968oNoZgxs_OJeTmc6A3krT7F5nE0Tbrt1Da6Hd-xvnN5cGI5ZwXEC7T9zqns7Nc/s1600/c+lang.png
https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhn3a87s02btTfomcvsZ9Md7J5ZSOq4PE3ClEWXgJBj3B8rHyN9zHh1lW_uqeimGG8T-zoLP_evbKr968oNoZgxs_OJeTmc6A3krT7F5nE0Tbrt1Da6Hd-xvnN5cGI5ZwXEC7T9zqns7Nc/s72-c/c+lang.png
COMPUTER SCIENCE SOLVED MCQS
https://cs-mcqs.blogspot.com/2017/08/solved-mcqs-on-c-programming.html
https://cs-mcqs.blogspot.com/
https://cs-mcqs.blogspot.com/
https://cs-mcqs.blogspot.com/2017/08/solved-mcqs-on-c-programming.html
true
1616963833964386058
UTF-8
Loaded All Posts Not found any posts VIEW ALL Readmore Reply Cancel reply Delete By Home PAGES POSTS View All RECOMMENDED FOR YOU LABEL ARCHIVE SEARCH ALL POSTS Not found any post match with your request Back Home Sunday Monday Tuesday Wednesday Thursday Friday Saturday Sun Mon Tue Wed Thu Fri Sat January February March April May June July August September October November December Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec just now 1 minute ago $$1$$ minutes ago 1 hour ago $$1$$ hours ago Yesterday $$1$$ days ago $$1$$ weeks ago more than 5 weeks ago Followers Follow THIS PREMIUM CONTENT IS LOCKED STEP 1: Share to a social network STEP 2: Click the link on your social network Copy All Code Select All Code All codes were copied to your clipboard Can not copy the codes / texts, please press [CTRL]+[C] (or CMD+C with Mac) to copy Table of Content