1.
#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;
int cmp = memcmp(&s1,&s2,sizeof(myStruct));
printf("%d", cmp);
}
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: An undefined value
---------------------------------------------------------
Select value(s) that are considered as "true". (For instance, in a test like if
(10) { ... } )
solution:
1,10,0.1,-1 (all select)
---------------------------------------------------------------------------
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);
}
What is printed by this code?
solution: world
--------------------------------------------------------------------
15.)
what value is returned by a program in case of a successful completion.
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;
To access the variable a from the p pointer, the statement is........
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: only optimize code when necessary.
-----------------------------------------------------------------
20.)
Enter the name of the function which releases memory.
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;
what is the value returned by sizeof(myUnion)?
solution: 1
--------------------------------------------------------------------------
23.)What is the value returned by fread() when the end of a file has been reached
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;
To Access to the Variable a of the structure s,the statement is...
Solution: s.a
-----------------------------------------------------------------------------------
-------
26)
int i1=5;
int i2=2;
int i3=i1/i2 ;
what is the value of i3?
Solution: 2
-----------------------------------------------------------------------------------
-------
27)What is the value returned by sizeof(int)?
Solution :It depends on the compiler and/or computer architecture
---------------------------------------------------------------------------
28)
int i;
for(i=0;i<10;i++)
{
}
What is the value of i after the for loop??
Solution :10
-----------------------------------------------------------------------------------
-----
29)Enter the name of the function which allocates memory.
Solution: malloc()
or 1)malloc 2)calloc /calloc() 3)realloc /realloc().
-----------------------------------------------------------------------
30)in base2 sytem(binary)what is the value of 11 & ~01?
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: It is better to include "foo.h" instead of void foo(); in main.c
-----------------------------------------------------------------------------------
----------
32) What is the index of the last element in an array of 19 elements?
solution: 18
-----------------------------------------------------------------------------------
---------------
33)Variable names are case sensitive.
solution :True
-----------------------------------------------------------------------------------
---------
34)Which of the following statements is a correct pointer declaration on an
integer?
solution: int *a;
-----------------------------------------------------------------------------------
----------
35)
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
-----------------------------------------------------------------------------------
--------
36)Which option is a valid constant declaration in C?
Answer: #define MAXSIZE 100
-----------------------------------------------------------------------------------
---------
37)Enter the name of the function which releases memory.
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");
}
}
what is printed by this code?
solution: foo
-----------------------------------------------------------------------------------
-------