MCQ (3)
MCQ (3)
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct
{
char a;
int b;
}myStruct;
void main()
{
myStruct s1;
s1.a = 'a';
s1.b = 2;
myStruct s2;
s2.a = 'a';
s2.b = 2;
solution: UNPREDICTABLE.
------------------------------------------------------------------------------
2.)
#include <stdio.h>
int main()
{
int i=0;
printf("%d", i++);
}
solution:- 0
--------------------------------------------------------------
3.)
#include <stdio.h>
int a()
{
printf("a");
return 0;
}
int b()
{
printf("b");
return 0;
}
void main()
{
if(a() & b())
{
printf("main");
}
}
solution:- ab
---------------------------------------
4.)
#include <stdio.h>
int a()
{
printf("a");
return 0;
}
int b()
{
printf("b");
return 0;
}
void main()
{
if(a() && b())
{
printf("main");
}
}
solution:- a
-------------------------------------------------------
5.)
#include <stdio.h>
int a()
{
printf("a");
return 0;
}
int b()
{
printf("b");
return 0;
}
void main()
{
if(a() || b())
{
printf("main");
}
}
solution:- ab
-------------------------------------------------------------
6.)
#include <stdio.h>
int a()
{
printf("a");
return 0;
}
int b()
{
printf("b");
return 0;
}
void main()
{
if(a() | b())
{
printf("main");
}
}
solution: ab
--------------------------------------------------------------
7.)
#include <stdio.h>
typedef struct
{
char a;
int b;
}myStruct;
void main()
{
myStruct s1;
s1.a = 'a';
s1.b = 3;
myStruct s2;
s2 = s1;
printf("%d", s2.b);
}
solution:3
--------------------------------------------------------------------
8.)
#include <stdio.h>
typedef struct
{
unsigned int i:1;
}myStruct;
void main()
{
myStruct s;
s.i = 1;
s.i++;
printf("%d", s.i);
}
solution:0
-------------------------------------------------------------------------
9.)
#include <stdio.h>
void main()
{
int a=1;
int *p = &a;
*p++;
printf("%d", a);
}
solution:1
------------------------------------------------------------------------
10.)
What is the result of 1 << 2 ?
solution: 4
-----------------------------------------------------------------------
11.)
What is printed by this code?
int a = 5;
int *p = &a;
printf("%d", p);
solution:
12.)
Among these two methodologies of development, which one do you recommend?
Methodology #1 :
Write the tests for the new functionality "F" Test that "F" fails Implement "F"
Test that "F" works
Methodology #2 :
Implement the new functionality "F" Write the tests for "F" Test that "F" works
solution: Methodology #1
13.)
You have to write a function which reads the content of a file and stores it in a
buffer.
This function receives a pointer on the buffer in its parameters.
Among these proposals, what is the most important to avoid bugs.
solution:
The function must receive the length of the given buffer.
-----------------------------------------------------------------------------------
-------
14.)
#include <stdio.h>
#include <unistd.h>
void main()
{
char const *p = "hello";
p = "world";
printf("%s", p);
}
solution: world
--------------------------------------------------------------------
15.)
solution: 0
---------------------------------------------------------------------
16.) in a base 2 system(binary), what is the value of 01 ^ 11?
solution: 10
---------------------------------------------------------------------
17.)
typedef struct
{
int a;
int b;
}struct_type;
struct_type s;
struct_type *p = &s;
solution: p -> s
-----------------------------------------------------------------------
18.)
In a base 2 system(binary), what is the value of 0001 & 0001?
solution: 0001
---------------------------------------------------------------------
19.) With c programming, it is important to...........
solution: free(ptr);
-----------------------------------------------------------
21.)
In the definition of a header file, it is better that this file.........
solution: includes all headers that are necessary to it's use, in order
not to have to include them from the source file where it is used.
--------------------------------------------------------------------------
22.)
typedef union
{
char a;
char b;
}myUnion;
solution: 0
-----------------------------------------------------------------
24)What is printed by this code
void main()
{
int a[]={10,15,9,12};
printf("%d",*(a+2));
Solution: 9
-----------------------------------------------------------------------------------
-------
25)
typedef struct
{
int a;
int b;
} struct_type;
struct_type s;
Solution: s.a
-----------------------------------------------------------------------------------
-------
26)
int i1=5;
int i2=2;
int i3=i1/i2 ;
Solution: 2
-----------------------------------------------------------------------------------
-------
27)What is the value returned by sizeof(int)?
Solution :10
-----------------------------------------------------------------------------------
-----
29)Enter the name of the function which allocates memory.
Solution: malloc()
Solution: 10
-----------------------------------------------------------------------
31)
File foo.h
#ifndef FOO_H_
#define FOO_H_
void foo();
#endif
File foo.c:
#include<stdio.h>
#include "foo.h"
void foo()
{
printf("hello");
}
File main.c
void foo();
void main()
{
foo();
}
This program should print "hello".what do you think about its architecture?
solution: 18
-----------------------------------------------------------------------------------
---------------
33)Variable names are case sensitive.
solution :True
-----------------------------------------------------------------------------------
---------
34)Which of the following statements is a correct pointer declaration on an
integer?
void main()
{
char buffer[50];
buffer[0]='h';
buffer[1]='e';
buffer[2]='l';
buffer[3]='l';
buffer[4]='o';
buffer[5]='\0';
buffer[6]='w';
buffer[7]='o';
buffer[8]='r';
buffer[9]='l';
buffer[10]='d';
buffer[11]='\0';
printf("%d",strlen(buffer));
}
solution : 5
-----------------------------------------------------------------------------------
--------
Solution :free()
-----------------------------------------------------------------------------------
-----------
38)
int m = 5 % 2;
What is the value of m
solution: 1
-----------------------------------------------------------------------------------
----------
39)
In the following code, what is the size of arr in bytes?
char arr[10] = {'a', 'b', 'c'};
solution:10
-----------------------------------------------------------------------------------
-----------
40)
int a = 10;
Which statement(s) returns the memory address of the variable a ?
solution: &a;
-----------------------------------------------------------------------------------
----------
41)
#include <stdio.h>
void main()
{
int a=1;
int b=2;
if((a=b))
{
printf("foo");
}
else
{
printf("bar");
}
}
solution: foo
-----------------------------------------------------------------------------------
-------