C/C /Computer Science Sample Test,Sample questions

Question:
 How many number of pointer (*) does C have against a pointer variable declaration?

1.7

2.127

3.255

4.No limits


Question:
 What is the output of the code below?

int main()
{
int i = 10;
int *const p = &i;
foo(&p);
printf("%d
", *p);
}
void foo(int **p)
{
int j = 11;
*p = &j;
printf("%d
", **p);
}

1.11 11

2.Undefined behaviour

3. Compile time erro

4.Segmentation fault/code-crash


Question:
 What is the output of this C code?

int *f();
int main()
{
int *p = f();
printf("%d
", *p);
}
int *f()
{
int *j = (int*)malloc(sizeof(int));
*j = 10;
return j;
}

1.10

2.Compile time error

3.Segmentation fault/runtime crash since pointer to local variable is returned

4.Undefined behaviour


Question:
 What is the output of this C code?

int main()
{
char *p = NULL;
char *q = 0;
if (p)
printf(" p ");
else
printf("nullp");
if (q)
printf("q
");
else
printf(" nullq
");
}

1. nullp nullq

2.Depends on the compiler

3. x nullq where x can be p or nullp depending on the value of NULL

4. p q


Question:
 What is the output of this C code?

int main()
{
int i = 10;
void *p = &i;
printf("%f
", *(float*)p);
return 0;
}

1.Compile time error

2.Undefined behaviour

3.10

4.0.000000


Question:
 What is the output of this C code?

int main()
{
printf("Hello World! %d 
", x);
return 0;
}

1.Hello World! x;

2. Hello World! followed by a junk value

3. Compile time error

4.Hello World!


Question:
 What is the output of this C code?

void main()
{
int k = 4;
float k = 4;
printf("%d", k)
}

1.Compile time error

2.4

3.4.0000000

4.4.4


Question:
 Which one is used during memory deallocation in C?

1. remove(p);

2. delete(p);

3.free(p);

4.terminate(p);


Question:
. C99 standard guarantess uniqueness of _____ characters for external names.

1.31

2.6

3.12

4.14


Question:
A variable declared in a function can be used in main?

1.True

2.False

3.True if it is declared static

4.None of the mentioned


Question:
All keywords in C are in?

1. Lower Case letters

2.Upper Case letters

3. Camel Case letters

4.None


Question:
C99 standard guarantees uniqueness of ____ characters for internal names.

1.31

2.63

3.12

4.14


Question:
calloc initialises memory with all bits set to zero.

1.True

2.False

3.Depends on the compiler

4.Depends on the standard


Question:
calloc() returns a storage that is initialized to.

1.Zero

2.Null

3.Nothing

4.One


Question:
Comment on the following?
const int *ptr;

1.You cannot change the value pointed by ptr

2.You cannot change the pointer ptr itselfC.

3.Both (a) and (b)

4.You can change the pointer as well as the value pointed by it


Question:
Comment on the output of this C code?

int main()
{
const int i = 10;
int *ptr = &i;
*ptr = 20;
printf("%d
", i);
return 0;
}

1.Compile time errorB. C. D. 10

2.Compile time warning and printf displays 20

3.Undefined behaviour

4.10


Question:
Comment on the output of this C code?

int main()
{
int a = 10;
int **c -= &&a;
}

1.You cannot apply any arithmetic operand to a pointer.

2.We don't have address of an address operator

3.Both (a) and (b)

4.None of the mentioned


Question:
Does this compile without error?

int main()
{
for (int k = 0; k < 10; k++);
return 0;
}

1.Yes

2.No

3.Depends on the C standard implemented by compilers

4.None of the mentioned


Question:
Does this compile without error?

int main()
{
int k;
{
int k;
for (k = 0; k < 10; k++);
}
}

1.Yes

2.no

3.Depends on the compiler

4.Depends on the C standard implemented by compilers


Question:
In function free(p), p is a:

1.int

2. Pointer returned by malloc()

3.Pointer returned by calloc()

4.Both b & c


Question:
Memory allocation using malloc() is done in?

1.Static area

2.Stack area

3.Heap area

4.Both b & c


Question:
On freeing a dynamic memory, if the pointer value is not modified, then the pointer points to?

1.NULL

2.Other dynamically allocated memory

3.The same deallocated memory location

4.It points back to location it was initialized with


Question:
The function ____ obtains block of memory dynamically.

1.calloc

2.malloc

3.Both a & b

4.free


Question:
The name of the variable used in one function cannot be used in another function?

1.True

2.False

3.May be

4.None of the mentioned


Question:
Variable name resolving (number of significant characters for uniqueness of variable) depends on?

1.Compiler and linker implementations

2.Assemblers and loaders implementations

3.C Language

4.None


Question:
Variable names beginning with underscore is not encouraged. Why?

1. It is not standardized

2.To avoid conflicts since assemblers and loaders use such names

3.To avoid conflicts since library routines use such names

4.To avoid conflicts with environment variables of an operating system


Question:
void * malloc(size_t n) returns:

1.Pointer to n bytes of uninitialized storage

2.NULL if the request cannot be satisfied

3.Nothing

4.Both a & b are true


Question:
What is the output of this C code?

int *f();
int main()
{
int *p = f();
printf("%d
", *p);
}
int *f()
{
int j = 10;
return &j;
}

1.10

2.Compile time error

3.Segmentation fault/runtime crash

4.Undefined behaviour


Question:
What is the output of this C code?

int main()
{
int *ptr, a = 10;
ptr = &a;
*ptr += 1;
printf("%d,%d/n", *ptr, a);
}

1.10,10

2.10,11

3.11,10

4.11,11


Question:
What is the output of this C code?

int main()
{
int a = 1, b = 2, c = 3;
int *ptr1 = &a, *ptr2 = &b, *ptr3 = &c;
int **sptr = &ptr1; //-Ref
*sptr = ptr2;
}

1.ptr1 points to aB. ptr1 points to bC. sptr points to ptr2D. None of the mentioned.

2.ptr1 points to b

3.sptr points to ptr2

4.None of the mentioned.


Question:
What is the output of this C code?

int main()
{
int i = 10;
int *p = &i;
foo(&p);
printf("%d ", *p);
printf("%d ", *p);
}
void foo(int **const p)
{
int j = 11;
*p = &j;
printf("%d ", **p);
}

1.11 11 11

2.11 11 Undefined-value

3.Compile time error

4.Segmentation fault/code-crash


Question:
What is the output of this C code?

int main()
{
int i = 10;
void *p = &i;
printf("%d
", (int)*p);
return 0;
}

1. Compile time error

2.Segmentation fault/runtime crash

3.10

4.Undefined behaviour


Question:
What is the output of this C code?

int main()
{
int i = 97, *p = &i;
foo(&i);
printf("%d ", *p);
}
void foo(int *p)
{
int j = 2;
p = &j;
printf("%d ", *p);
}

1.2 97

2.2 2

3.Compile time error

4.Segmentation fault/code crash


Question:
What is the output of this C code?

int main()
{
int i = 97, *p = &i;
foo(&p);
printf("%d ", *p);
return 0;
}
void foo(int **p)
{
int j = 2;
*p = &j;
printf("%d ", **p);
}

1.2 2

2.2 97

3. Undefined behaviour

4.Segmentation fault/code crash


Question:
What is the output of this C code?

int main()
{
int y = 10000;
int y = 34;
printf("Hello World! %d
", y);
return 0;

1.Compile time error

2.Hello World!

3.True

4.None of the mentioned


Question:
What is the output of this C code?

int main()
{
j = 10;
printf("%d
", j++);
return 0;
}

1.10

2.11

3.Compile time error

4.0


Question:
What is the output of this C code?

int x = 0;
void main()
{
int *const ptr = &x;
printf("%p
", ptr);
ptr++;
printf("%p
 ", ptr);
}

1.0 1

2.Compile time error

3.0xbfd605e8 0xbfd605ec

4.0xbfd605e8 0xbfd605e8


Question:
What is the output of this C code?

int x = 0;
void main()
{
int *ptr = &x;
printf("%p
", ptr);
x++;
printf("%p
 ", ptr);
}

1.Same address

2.Different address

3.Compile time error

4.Varies


Question:
What is the output of this C code?

void foo(const int *);
int main()
{
const int i = 10;
printf("%d ", i);
foo(&i);
printf("%d", i);
}
void foo(const int *i)
{
*i = 20;
}

1.Compile time error

2.10 20

3.Undefined value

4.10


Question:
What is the output of this C code?

void foo(float *);
int main()
{
int i = 10, *p = &i;
foo(&i);
}
void foo(float *p)
{
printf("%f
", *p);
}

1.10.000000

2.0.000000

3.Compile time error

4.Undefined behaviour


Question:
What is the output of this C code?

void foo(int*);
int main()
{
int i = 10, *p = &i;
foo(p++);
}
void foo(int *p)
{
printf("%d
", *p);
}

1.10

2.Some garbage value

3.Compile time error

4.Segmentation fault


Question:
What is the output of this C code?

void foo(int*);
int main()
{
int i = 10;
foo((&i)++);
}
void foo(int *p)
{
printf("%d
", *p);
}

1.10

2.Some garbage value

3.Compile time error

4.Segmentation fault/code crash


Question:
What is the output of this C code?

void main()
{
char *p = calloc(100, 1);
p = "welcome";
printf("%s
", p);
}

1.Segmentation fault

2.garbage

3.Error

4.welcome


Question:
What is the output of this C code?

void main()
{
int a[3] = {1, 2, 3};
int *p = a;
int **r = &p;
printf("%p %p", *r, a);
}

1.Different address is printed

2.1

3.Same address is printed

4.1 1


Question:
What is the output of this C code?

void main()
{
int a[3] = {1, 2, 3};
int *p = a;
int *r = &p;
printf("%d", (**r));

1.1

2.Compile time error

3.Address of a

4. Junk value


Question:
What is the output of this C code?

void main()
{
int k = 5;
int *p = &k;
int **m = &p;
**m = 6;
printf("%d
", k);
}

1.5

2.Compile time error

3.6

4.Junk


Question:
What is the output of this C code?

void main()
{
int k = 5;
int *p = &k;
int **m = &p;
printf("%d%d%d
", k, *p, **m);
}

1.5 5 5

2.5 5 junk value

3.5 junk value

4.Run time error


Question:
What is the output of this C code?

void main()
{
int k = 5;
int *p = &k;
int **m = &p;
printf("%d%d%d
", k, *p, **p);
}

1.5 5 5

2. 5 5 junk value

3. 5 junk value

4.Compile time error


Question:
What is the output of this C code?

void main()
{
int x = 0;
int *ptr = &5;
printf("%p
", ptr);
}

1.5

2. Address of 5

3.Nothing

4.Compile time error


Question:
What is the output of this C code?

void main()
{
int x = 0;
int *ptr = &x;
printf("%d
", *ptr);
}

1.Address of x

2.Junk value

3.0

4.Run time error


Question:
What is the output of this C code?

void main()
{
int x = 0;
int *ptr = &x;
printf("%p
", ptr);
ptr++;
printf("%p
 ", ptr);
}

1. 0xbfd605e8 0xbfd605ec

2.0xbfd605e8 0cbfd60520

3.0xbfd605e8 0xbfd605e9

4.Run time error


Question:
What is the problem in following variable declaration?
      float 3Bedroom-Hall-Kitchen?;

1.The variable name begins with an integer

2.The special character '-'

3.The special character '?'

4.All of the mentioned


Question:
What substitution should be made to //-Ref such that ptr1 points to variable C?

int main()
{
int a = 1, b = 2, c = 3;
int *ptr1 = &a;
int **sptr = &ptr1;
//-Ref
}

1.*sptr = &c;

2. **sptr = &c;

3.*ptr1 = &c;

4.None of the mentioned


Question:
What will happen if the below program is executed?

int main()
{
int main = 3;
printf("%d", main);
return 0;
}

1.It will cause a compile-time error

2. It will cause a run-time error

3.It will run without any error and prints 3

4.It will experience infinite looping


Question:
Which is an indirection operator among the following?

1.&

2.*

3.->

4. .


Question:
Which is false ?

1.A variable defined once can be defined again with different scope

2. A single variable cannot be defined with two different types in the same scope

3.A variable must be declared and defined at the same time

4.A variable refers to a location in memory


Question:
Which is valid C expression?

1.int my_num = 100,000;

2.int my_num = 100000;

3. int my num = 1000;

4. int $my_num = 10000;


Question:
Which of the following are correct syntaxes to send an array as a parameter to function:
A. func(&array);

1.func(array);

2.func(array);

3. func(*array);

4.func(array[size]);


Question:
Which of the following cannot be a variable name in C?

1.Volatile

2.True

3.friend

4.export


Question:
Which of the following cannot be a variable name in C?

1.Volatile

2.True

3.friend

4.export


Question:
Which of the following declaration is not supported by C?

1.String str

2.char *str;

3.float str = 3e2

4.Both (a) and (c)


Question:
Which of the following declaration throw run-time error?

1.int **c = &c;

2.int **c = &*c;

3. int **c = **c

4.None of the mentioned


Question:
Which of the following does not initialize ptr to null (assuming variable declaration of a as int a=0)?

1.int *ptr = &a;

2. int *ptr = &a "“ &a;

3. int *ptr = a "“ a;

4.All of the mentioned


Question:
Which of the following format identifier can never be used for the variable var?

int main()
{
char *var = "Advanced Training in C by AllIndiaExams.com";
}

1.%f

2.%d

3.%c

4. %s


Question:
Which of the following is not a pointer declaration?

1.char a[10];

2.char a[] = {'1', '2', '3', '4'};

3.char *str;

4.char a;


Question:
Which of the following is not a valid C variable name?

1.int number;

2.float rate;

3.int variable_count;

4.int $main;


Question:
Which of the following is not a valid variable name declaration?

1.int __a3;

2.int __3a;

3.int __A3;

4.None of the mentioned


Question:
Which of the following is true for variable names in C?

1.They can contain alphanumeric characters as well as special characters

2.It is not an error to declare a variable to be one of the keywords(like goto, static)

3.Variable names cannot start with a digit.

4.Variable can be of any length.


Question:
Which of the following will return a result most quickly for searching a given key?

1.Unsorted Array

2.Sorted Array

3.Sorted linked list

4.Binary Search Tree


Question:
Why do we write (int *) before malloc?
     int *ip = (int *)malloc(sizeof(int));

1.It is for the syntax correctness

2.It is for the type-casting

3. It is to inform malloc function about the data-type expected

4.None of the mentioned


More MCQS

  1. C++ Programming MCQS Set-1
  2. C++ Multiple Choice Questions Set-1
  3. C++ Multiple Choice Questions Set-2
  4. C++ Programming MCQS Set-2
  5. C++ Programming MCQS Set-3
  6. C++ Programming MCQS Set-4
  7. C++ (CPP) MCQ Question with Answer
  8. Advanced c++ multiple choice question(MCQS)
  9. OOPS Quiz Questions and Answers(MCQS)
  10. C Programming - MCQ Questions Set 1
  11. C Programming - MCQ Questions Set 2
  12. C Programming - MCQ Questions Set 3
  13. C Programming - MCQ Questions Set 4
  14. C Programming - MCQ Questions Set 5
  15. C++ programming language MCQ Questions Set 1
  16. C++ programming language MCQ Questions Set 2
  17. C++ programming language MCQ Questions Set 3
  18. C++ programming language MCQ Questions Set 4
  19. C++ programming language MCQ Questions Set 5
  20. C++ Programming -Constructors and Destructors
  21. C++ Programming -OOPS Concepts
  22. C++ Programming - References
  23. C++ Programming - Functions
  24. C MCQS:-The ABC of C
  25. C MCQS Interview Questions
  26. C++ Questions and Answers – OOPs Basic Concepts
  27. C++ Questions and Answers – Returning Objects
  28. C Programming MCQ Part 1
  29. C Programming MCQ
  30. Computer Science & Engineering C Multiple Choice Questions set 1
  31. Computer Science & Engineering C Multiple Choice Questions set 2
  32. C Multiple Choice Questions C Functions Set 1
  33. C Multiple Choice Questions C Functions Set 2
  34. C Multiple Choice Questions C Operators
  35. C Multiple Choice Questions & AnswersConditional Expressions
  36. C Multiple Choice Questions & Answers Data Types
  37. C Multiple Choice Questions & Answers File Access
  38. Computer Science & Engineering Cloud Computing MCQs Part 1
Search
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!