KEMBAR78
All Mca C Programming | PDF | Pointer (Computer Programming) | Variable (Computer Science)
0% found this document useful (0 votes)
9 views17 pages

All Mca C Programming

The document contains a comprehensive set of questions and answers related to the C programming language, covering topics such as variable names, data types, operators, control flow, functions, and arrays. Each unit addresses specific concepts and provides examples to illustrate the principles of C programming. It serves as a study guide for understanding fundamental C programming concepts and syntax.

Uploaded by

costasmujnotes
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views17 pages

All Mca C Programming

The document contains a comprehensive set of questions and answers related to the C programming language, covering topics such as variable names, data types, operators, control flow, functions, and arrays. Each unit addresses specific concepts and provides examples to illustrate the principles of C programming. It serves as a study guide for understanding fundamental C programming concepts and syntax.

Uploaded by

costasmujnotes
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 17

UNIT 1:

1. Who is the father of C language?


ANS: Dennis Ritchie

2. Which of the following is not a valid C variable name?


ANS: int $main

3. All keywords in C are in ____________.


ANS: LowerCase letters

4. Which of the following is true for variable names in C?


ANS: Variable names cannot start with a digit

5. Which is a valid C expression?


ANS: int my_num = 100000;

6. Which of the following cannot be a variable name in C?


ANS: volatile

7. What is short int in C programming?


ANS: Short is the qualifier and int is the basic data type

8. Which of the following declaration is not supported by C


language?
ANS: Both "String str;" and "float str = 3e2;"

9. Which keyword is used to prevent any changes in the variable


within a C program?
ANS: const

10. What is the result of logical or relational expression in C?


ANS: 0 or 1
11. What will be the output of the following C code?
#include <stdio.h>
int main() {
printf("Hello World! %d \n", x);
return 0;
}
ANS: Compile time error (Variable x is not declared.)

12. Which of the following is not a valid variable name


declaration?
ANS: int PI = 3.14;

13. What is the problem in the following variable declaration -


float 3Be-b?;
ANS: The variable name begins with an integer

14. The format identifier ‘%i’ is also used for which data type?
ANS: int

15. Which data type is most suitable for storing a number


65000 in a 32-bit system?
ANS: unsigned short

UNIT 2:
1. What will be the output of the following C code?
#include <stdio.h>
int main() {
int a = 1, b = 1, d = 1;
printf("%d, %d, %d", ++a + ++a + a++, a++ + ++b, ++d + d++ +
a++);
}
ANS: Undefined (Compiler Dependent)
2. For which of the following, PI++; code will fail?
ANS: #define PI 3.14

3. What will be the output of the following C code?


#include <stdio.h>
int main() {
int a = 10, b = 10;
if (a = 5)
b--;
printf("%d, %d", a, b--);
}
ANS: a = 5, b = 9
4. What will be the output of the following C code?
#include <stdio.h>
int main() {
int i = 0;
int x = i++, y = ++i;
printf("%d %d\n", x, y);
return 0;
}
ANS: 0, 2

5. What will be the output of the following C code?


#include <stdio.h>
void main() {
int x = 97;
int y = sizeof(x++);
printf("X is %d", x);
}
ANS: x is 97
6. A negative number is actually a positive constant preceded by
a unary.
ANS: minus (-)

7. <, <=, >, and >= are ________ operators.


ANS: relational

8. The _______ operator takes two true/false values and


produces a true result if both operands are true.
ANS: && (Logical AND)

9. The _______ operator takes two true/false values and


produces a true (1) result if either operand is true.
ANS: || (Logical OR)

10. The ____ operator takes a single true/false value and


negates it, turning false to true and true to false.
ANS: ! (Logical NOT)

11. Which of the following is a ternary operator?


ANS: ?:

12. Which function returns the natural logarithm of d?


ANS: log(d)

13. To round down to the next integer value, the function used
is _____.
ANS: floor()
14. i = i + 1 is equivalent to ________.
ANS: both i+=1 and ++i
15. The sizeof operator returns the number of ______ the
operand occupies.
ANS: bytes

UNIT 3:
1. When the accuracy provided by a float number is not
sufficient, the type _______ can be used to define the
number.
ANS: double

2. On a 16-bit machine, float occupies ________ bits.


ANS: 32

3. On a 16-bit machine, double occupies ________ bits.


ANS: 64

4. C permits mixing of constants and variables of different


types in an expression.
ANS: TRUE

5. If the operands are of different types, the ‘lower’ type is


automatically converted to the ‘higher’ type before the
operation proceeds.
ANS: TRUE

6. When one of the operands is real and the other is integer, the
expression is called a _________ arithmetic expression.
ANS: mixed-mode

7. The value of the expression 22.0/10 is ________.


ANS: 2.2
8. The process of such local conversion is known as ________
a value.
ANS: casting

9. In which expression is a converted to an integer and then


added to b?
ANS: Z= (int) a + b

10. In 16-bit computers, characters are usually stored in ____


bits of internal storage.
ANS: 8
11. Keywords are the ______ words of a programming
language.
ANS: reserved

12. ____________ writes one character to the standard output.


ANS: putchar()

13. EOF stands for


ANS: end of file

14. The EOF value is returned by function _________.


ANS: getchar()

15. Input data can be entered into the computer from a


standard input device by meANS of the standard C library
function_____.
ANS: scanf()

UNIT 4:
1. Control the flow of execution of statements using two-way
decision and multipath decision.
ANS: TRUE (C supports if-else for two-way decisions and
switch-case for multipath decisions.)

2. In C, one can branch unconditionally from one point to another


in the program.
ANS: TRUE (Using goto, one can jump to any part of the
program.)

3. C does not support the goto statement to branch unconditionally


from one point to another in the program.
ANS: FALSE (C does support goto, though it is not
recommended for structured programming.)

4. ______ breaks the normal sequential execution of the program.


ANS: goto (It forces an unconditional jump to a labeled
statement.)

5. Is it possible to nest one if statement inside another?


ANS: yes (Nested if statements are commonly used for complex
conditions.)

6. When you have one if statement (or loop) nested inside another,
it's a very good idea to use _________.
ANS: explicit braces {} (Braces make the nested structure clear
and prevent logical errors.)

7. What is a conditional operator?


ANS: ?: (The conditional (ternary) operator condition ? expr1 :
expr2 evaluates a condition and returns one of two values.)

8. The conditional operator (?:) takes _____ operands.


ANS: 3 (It is a ternary operator requiring three operands.)
9. The _____ statements are a substitute for long if statements.
ANS: switch case (Instead of multiple if-else statements, switch-
case is used for better readability and efficiency.)
10. The default case in switch case is optional.
ANS: TRUE (The default case is not mandatory, but it is
recommended to handle unexpected inputs.)

11. The conditional operator does not produce a value.


ANS: TRUE (It returns a value, not a variable reference, so it
cannot be assigned to.)

12. Switch statement is a conditional branching statement.


ANS: TRUE (It evaluates an expression and executes different
cases based on the result.)

13. __________ is an entry-controlled loop.


ANS: while (It checks the condition before executing the loop
body.)

14. A while loop starts out like an if statement.


ANS: TRUE (The while loop checks a condition just like an if
statement before execution.)

15. The _______ loop is used in a situation where we need to


execute the body of the loop before the test is performed.
ANS: do…while (Unlike while, do…while executes at least
once before checking the condition.)

UNIT 5:
1. A ________ is a self-contained program segment that carries out
some specific, well-defined task.
ANS: function (A function is a reusable block of code that
performs a specific task.)

2. A function can be declared externally?


ANS: TRUE (Functions can be declared externally using extern
keyword.)
3. In C call by value, means that a function receives ______ of the
values of its arguments.
ANS: copies (Call by value means a function receives copies of
the arguments, not their actual memory addresses.)

4. The function main() is optional in a C program.


ANS: FALSE (main() is mandatory in every C program as it
serves as the entry point.)

5. The return data type, function name and the list of formal
parameters enclosed in brackets are separated by
_______________.
ANS: , (Commas are used to separate parameters in a function
declaration.)

6. Can a function not return anything?


ANS: TRUE (A function can have a void return type, meaning it
does not return a value.)

7. The ______ directive arranges all of the declarations within


stdio.h.
ANS: #include (#include is used to include standard or user-
defined header files.)

8. __________ is a process by which a function calls itself


repeatedly.
ANS: Recursion (Recursion is when a function calls itself to
solve smaller instances of a problem.)
9. The Towers of Hanoi is a game played with ___ poles and a
number of ____ sized disks.
ANS: 3, different (Towers of Hanoi uses three poles and
multiple disks of different sizes.)
10. A stopping condition must be there in a recursive
definition.
ANS: TRUE (Without a stopping condition, recursion leads to
infinite function calls.)

11. A function is a self-contained program segment that carries


out some specific, well-defined task.
ANS: TRUE (Functions help in modular programming by
breaking the program into smaller parts.)

12. The idea behind a function is that it ____ part of the


program.
ANS: encapsulates (Encapsulation means wrapping code inside
a function for reusability and clarity.)

13. The function prototype is not a function declaration.


ANS: FALSE (A function prototype is a declaration that informs
the compiler about a function's existence.)

14. Recursion is a process by which a function calls itself


repeatedly, until some specified condition has been met.
ANS: TRUE (Recursion continues until a base condition is
satisfied.)

15. We cannot have 2 or more recursive functions in a


program.
ANS: FALSE (Multiple recursive functions can exist in a
program for solving different problems.)

UNIT 6:
1. What is the scope of an automatic variable?
ANS: Within the block it appears (Automatic variables are local
to the block in which they are declared.)

2. Automatic variables are allocated space in the form of a


__________
ANS: stack (Automatic variables are stored in the stack
memory.)

3. Which of the following is a storage specifier?


ANS: auto (auto is a storage class specifier in C.)

4. If storage class is not specified for a local variable, then the


default class will be auto.
ANS: True (Local variables without a specified storage class are
automatically auto.)

5. Automatic variables are stored in ________


ANS: stack (Automatic variables reside in the stack segment.)

6. What linkage does automatic variables have?


ANS: No linkage (Automatic variables are local to the function
and have no linkage.)

7. Automatic variables are _________


ANS: Declared within the scope of a block, usually a function
(They are defined inside functions or blocks.)
8. When does the compiler accept the request to use a variable as a
register?
ANS: It is stored in CPU (Register variables are stored in CPU
registers for fast access.)
9. What is the scope of an automatic variable?
ANS: Exist only within that scope in which it is declared (They
are valid only within the block where they are defined.)

10. Automatic variables are allocated memory in


___________
ANS: stack (Stack memory is used for automatic variable
allocation.)

11. Automatic variables are initialized to ___________


ANS: Junk value (Automatic variables hold garbage values
unless explicitly initialized.)

12. Which of the following storage class supports char data


type?
ANS: all of the mentioned (auto, static, and register can store
char values.)

13. A local variable declaration with no storage class specified


is by default _
ANS: auto (If no storage class is mentioned, auto is assumed.)

14. Which data type can be stored in a register?


ANS: int (Usually int is stored in registers, but float and long are
generally not supported.)
15. Register variables reside in _
ANS: registers (Register variables are stored in CPU registers,
not memory.)

UNIT 7:
1. Which keyword is used to make the array size optional in C
language during array declaration?
ANS: extern (The extern keyword allows an array to be declared
without specifying its size.)

2. Which of the following is the correct syntax to send an array as


a parameter to a C function?
ANS: Both func(array) and func(&array); (Arrays are passed by
reference using their base address.)

3. An array of similar data types which themselves are a collection


of dissimilar data type are
ANS: Array of Structure (An array of structures stores multiple
structures that contain different data types.)

4. Comment on an array of the void data type.


ANS: You cannot have an array of void data type (Void has no
size, so an array of void is invalid.)

5. What is the data type of the array passed from the command line
into the main() function in C?
*ANS: char arr[]; (char *argv[] is used in main(int argc, char
*argv[]).)

6. In C, arrays are zero-based?


ANS: TRUE (Array indices start from 0 in C.)

7. The subscript which specifies a single element of an array is an


integer expression in ____ brackets
ANS: square ([] brackets are used for array subscripts.)
8. Subscripted array references can appear on either side of the
assignment operator?
ANS: TRUE (Arrays can be used in expressions and as left-hand
values.)

9. Can an entire array be passed to the function?


ANS: TRUE (Arrays are passed by reference, allowing entire
arrays to be passed.)

10. In a two-dimensional matrix, the first subscript in the


declaration specifies the number of ________________.
ANS: row (The first index represents the number of rows.)

11. In a two-dimensional matrix, the second subscript in the


declaration specifies the number of ________________.
ANS: column (The second index represents the number of
columns.)

12. The destination string is strcpy's second argument?


ANS: FALSE (The destination string is the first argument in
strcpy(dest, src), and the source is the second.)

13. Is this statement correct: int i = '1';


ANS: yes (Character literals in single quotes are stored as their
ASCII values, so this is valid.)

14. The library function atoi can be used for any string.
ANS: FALSE (atoi only works for strings representing valid
integers; other input may cause undefined behavior.)

15. The library function used to copy one string to another


is__________.
ANS: strcpy (strcpy(dest, src) copies the contents of one string
into another.)
UNIT 8:
1. What is the base data type of a pointer variable by which the
memory would be allocated to it?
ANS: No datatype (A pointer itself has no datatype, but it
stores the address of a specific datatype.)

2. Prior to using a pointer variable it should be


ANS: Both declared and initialized (A pointer must be
declared and initialized before use to avoid undefined behavior.)

3. In C, a pointer variable to an integer can be created by the


declaration
ANS: int p; (Correct syntax for declaring a pointer to an integer.

4. A pointer variable can be


ANS: Passed to a function, Changed within a function,
Returned by a function (Pointers can be passed, modified, and
returned in functions.)

5. Is the NULL pointer the same as an uninitialized pointer?


ANS: False (A NULL pointer has a defined value (0), while an
uninitialized pointer contains garbage data.)

6. What is a wild pointer?


ANS: Pointer which is not initialized (A wild pointer has an
undefined value, leading to unpredictable behavior.)

7. Address stored in the pointer variable is of type __


ANS: Integer (Memory addresses are stored as integer values.)
8. Comment on const int *ptr;
ANS: You cannot change the value pointed by ptr (A const
int * means the pointer can be changed, but the value it points to
cannot.)

9. The operator > and < are meaningful when used with
pointers if
ANS: The pointers point to elements of the same array
(Comparisons work only within the same array for pointer
arithmetic.)

10. The reason for using pointers in a C program is


ANS: All of the above (Pointers allow variable sharing,
efficient structure passing, and linked data structures.)

11. A pointer is a
ANS: Variable that stores the address of another variable (A
pointer holds the memory address of another variable.)

12. How can you write a[i][j][k][l] in equivalent pointer


expression?
ANS: ((((a+i)+j)+k)+l) (This expression correctly dereferences
the 4D array.)

13. Comment on the following pointer declaration? int


*ptr, p;
ANS: ptr is a pointer to an integer, p is not (ptr is a pointer,
but p is a regular integer variable.)
14. The address operator & cannot act on
ANS: Both of the above (The & operator cannot be used on R-
values or arithmetic expressions.)
15. Check whether the condition is correct or not? int **a;
ANS: is syntactically and semantically correct (int **a; is
valid and represents a pointer to a pointer.)

You might also like