C the SEA by Narendra
Transcript of C the SEA by Narendra
7/29/2019 C the SEA by Narendra
http://slidepdf.com/reader/full/c-the-sea-by-narendra 1/13
C the SEA Extreme
programming In this exam you are being tested in all the aspects like practical and
theoretical knowledge, ability of reading books, research skills,
Mathematical approach with C ,debugging skills , awareness of
different compilers and latest C standards.
Syllabus :
C on UNIX/Linux/Solaris, DOS / WINDOWS platforms with
Simple Assembly ,
Basics of systems programming,
Basic system calls (API),
Basics of Network programming ( Sockets ),
Basics of Threading (POSIX),
Basics of Inter Process Communication ( IPC - System V, POSIX and
Solaris,Windows ),
Basics of virus programming.
By considering duration of the exam, we are not concentrated
on the fallowing areas in which C is mainly used:
Hardware interaction programs (Device drivers, TSR’s, Kernel
designing, Embedded systems etc), Applications of Advanced Data
Structures (Database designing, Kernel designing, Image
processing,Memory management algorithms, Network routing
algorithms, Graphics etc) and many more concepts are there…
Compilers used:
Turbo C 2.01(DOS), Turbo C++ 4.5 (Windows),
TCC
Duration: 2½ Hrs
7/29/2019 C the SEA by Narendra
http://slidepdf.com/reader/full/c-the-sea-by-narendra 2/13
GNU compiler kit with rpcgen compiler
(UNIX/Linux/Windows/Solaris). GCC
Visual C/C++ Express edition (Windows)
VCC
There are 5 sections: (50 questions 100 credits)
0x 0001) PUNCH (the challenge) One question 25credits
0x 0002) EASY 20 questions 20 credits
0x 0003) MEDIUM 15 questions 15 credits
0x 0004) HARD 10 questions 20 credits
0x 0005) TOUGH 4 questions 20 credits
Section 0x0001 PUNCH
1) Can you run a C-program without ‘main ()’ function?Note: Don’t use preprocessors
First choose correct answer from below two answers then support the
answer with your explanation by answering relevant questions.
Ans: 1) we can’t .Only we can compile. Why?
Is there any standard which restricts C-program to start from
**Your answers should be simple
and clear.
Note 1: We mentioned the compiler (TCC or GCC or VCC) with question
number, based on which you have to answer. If it is general question no
compiler is mentioned.
7/29/2019 C the SEA by Narendra
http://slidepdf.com/reader/full/c-the-sea-by-narendra 3/13
‘main’?
Ans: 2) we can. How?
Then describe the steps to execute a C-program without ‘main’
using any compiler on any platform
Section 0x0002 EASY
1)Which software is not developed in C?
a) UNIX b) Java c) Python d) All of the above
2) sizeof (long long int) =?
a) No such data type: compiler error b) No error: 4c) No error: 8 d) Execution error
3) Is there any error in the following program?
include<stdio.h>
int main()
{
void *p=(void *)2000;
*p=40;
printf(“%d”,*p);
return 0;
}
7/29/2019 C the SEA by Narendra
http://slidepdf.com/reader/full/c-the-sea-by-narendra 4/13
4) What does following code…actually?
x^= y^= x^=y;
5) Which is equivalent expression for x%16 in C?
a) x mod 16 b) x & 15 c) x | 8 & x ^ 8 d) x ^ 16
6) What is ‘nul’ character and what is NULL pointer?
7) main () returns a value to __________.
Exactly in which location this value will be stored______.
8) What is the value of EOF marker_____?
9) putchar (4[“abcdefg”]); Output=?
10) What is ‘coercion’?
GCC 11) Output=? #include<stdio.h>
#include<stdlib.h>
int main()
{
fork();
printf("ORKIT");
return 0;
}
12) int (*(*p[5])(int (*[3]) (char))[10]; What is p?
13) Ouput=?
#include <stdio.h>
main()
{
float *p=4040,*q=4000;
printf("%d",p-q);
}
a)Implemantaion dependent b)Question wrong
c)40 d 10
TCC14) If sizeof (int) =2 then Output=?
7/29/2019 C the SEA by Narendra
http://slidepdf.com/reader/full/c-the-sea-by-narendra 5/13
#include<stdio.h>
int main()
{
long i,j,k;
i =32767+300;
printf("%ld",i);
return 0;
}
a) -32469 b)33067 c)32468 d) None
15) What is the relation between volatile and compiler
optimization
16) Output= ?
#include<stdio.h>
int main()
{
char *p;
p="Hello";
printf("%c\n",*&*&*p);
}
17) Output = ?
#define square(x) x*x
main()
{int i;
i = 64/square(4);
printf("%d",i);
}
18) Output =?
#define f(g,g2) g##g2
7/29/2019 C the SEA by Narendra
http://slidepdf.com/reader/full/c-the-sea-by-narendra 6/13
int main()
{
int var12=100;
printf("%x",f(var,12));
}
19) The format specified for pointer is?
a) % [*] b) %p c) %& d) No format specifier exist
20) Where the auto variables stored?
a) Data b) Code c) Stack d) Depends on memory model
Section 0x0003 MEDIUM
GCC 1) What is Door in Solaris IPC and what is Call-by-copy-
restore ?
GCC 2) Using which system call you can create user defined
threads ,if there is no threads package available for your
platform?
a) Pthread_create () b) clone (); 3) fork ();
4) vfork ();
Ans:clone();
TCC 3) What does the error 'Null Pointer Assignment' means
and what causes this error?
4) List out any 10 IPC mechanisms (Just mention their names)?
5) How can you read the whole environment? Write simple
program?
Ans:#include <stdio.h>
int main(int argc, char **argv, char **envp)
{
char *p;
while ((p = *envp++))
7/29/2019 C the SEA by Narendra
http://slidepdf.com/reader/full/c-the-sea-by-narendra 7/13
printf("%s\n", p);
return 0;
}
6) If domain values of x=any long unsigned and y=2, 3, 4,…,
16
Then what does process () actually…?
char * process( long unsigned x,unsigned short int y)
{
Char *p=calloc(33,1);
do
{
*p++=”0123456789ABCDEF”[x%y];
x/=y;
} while(x! =0);
strrev (p);
return p;
}
7) Difference between 'int' and 'short int'?
8) What is a far pointer and what is raw socket?
TCC 9) What is a “floating point not linked” error in Turbo C?
10) Write a program to multiply x with 7 without using + and
* operators and looping statements where x is unsigned int?
11) Output=?
#include <stdio.h>
int add(int,int);
main()
{ printf("%d",add(20,30));
}
int add(int x , int y)
{ asm
7/29/2019 C the SEA by Narendra
http://slidepdf.com/reader/full/c-the-sea-by-narendra 8/13
{ mov ax,x
mov bx,y
sub ax,bx
} }
GCC 12 )what is the exact output ,if pid != -1?
#include<stdio.h>
#include<stdlib.h>
#include<unistd.h>
int main()
{
int pid;
pid = fork();
switch(pid){
case -1: printf("Thread creation error!");
exit(1);
case 0: printf("Dad first! ");
_exit (0);
default: wait (0);
printf("Child first! ");
exit (0); }
}
a) Dad first! Child first! b) Child first! Dad first!
c) We can't predict d) Implementation dependent
13)How can you extract and print the value (in Hexa decimal )of most significant nibble from a character(ASCII).e.g. chara=0x3A;
you have to extract and print 3
14) Which #pragma options are used for storage alignmentsand inline assembly?15)What is short-circuit evaluation?
Section 0x0004 HARD
7/29/2019 C the SEA by Narendra
http://slidepdf.com/reader/full/c-the-sea-by-narendra 9/13
1) Is Dennis Ritchie still alive? And who is the personat first paper of this question paper?
2) Write a small C program to determine whether a machine's
byte order type is little-endian or big-endian.
3) Traverse the given tree using Level-order and Hill-climb
traversal
4) List out any 20 standard C reference or text books withauthors and
List out Any 5 C - compilers from different vendors?
5) Can you write a file–virus in C?6) What does the following program
#include<stdio.h>
#include<sys/types.h>
#include<sys/socket.h>
#include<signal.h>
#include<unistd.h>
#include<arpa/inet.h>
#include<netinet/in.h>
#include<stdlib.h>
int count;
void sigchld_handler(int);
int main()
A
B C
D E F G
H I J
Given tree:
7/29/2019 C the SEA by Narendra
http://slidepdf.com/reader/full/c-the-sea-by-narendra 10/13
{
int sfd,cfd;
int slen,clen;
char ch;
struct sockaddr_in saddr,caddr;
sfd=socket(AF_INET,SOCK_STREAM,0);
saddr.sin_family=AF_INET;
saddr.sin_addr.s_addr=inet_addr("127.0.0.1");
saddr.sin_port=9876;
slen=sizeof(saddr);
bind(sfd,(struct sockaddr*)&saddr,slen);
listen(sfd,5);
signal(SIGCHLD,sigchld_handler);
while(1)
{
printf("Server is waiting!.......\n");
clen=sizeof(caddr);
cfd=accept(sfd,(struct sockaddr*)&caddr,&clen);
if(fork()==0)
{
read(cfd,&ch,1);
printf("server : I recieved %c \n", ch);
sleep(5);
/*** client request processing . . . ***/
ch++;
printf("server : And I'm sending %c \n", ch);
write(cfd,&ch,1);
close(cfd);
exit(0);
}
else
7/29/2019 C the SEA by Narendra
http://slidepdf.com/reader/full/c-the-sea-by-narendra 11/13
{
close(cfd);
if(++count==5)
wait(0);
} } }
void sigchld_handler(int sig)
{
printf("child died!\n");
count--;
}
7) if u compile and run following program on UNIX based
systems as falllows....
$ gcc -D_REENTRANT -o thread Threads.c -lpthread
$ ./thread
Can u predict the output of the program! If so , what is it?
#include<unistd.h>
#include<stdlib.h>
#include<pthread.h>
#include<stdio.h>
#include<string.h>
void * run(void *);
struct info
{
int no;
char msg[100];
};
int main()
{
int res,i;
pthread_t thread[3];
7/29/2019 C the SEA by Narendra
http://slidepdf.com/reader/full/c-the-sea-by-narendra 12/13
void * thr_res;
struct info d;
for(i=0;i<3;i++)
{
d.no=i+1;
strcpy(d.msg,"\'cooky\'");
res = pthread_create(&thread[i],NULL,run,(void*)&d);
printf("\nThread %d started...\n\n",i+1);
if(res!=0)
{
perror("Thread creation failed!\n\n");
exit(1);
}
sleep(1);
printf("Waiting for thread : %d to finish! ...\n\n",i+1);
res = pthread_join(thread[i],&thr_res);
if(res!=0)
{
perror("Thread join failed!\n\n");
exit(1);
}
printf("Thread :%d joined,it returned with msg : %s
\n\n",d.no,d.msg);
}
printf("All threads joined!\n\n");
exit(0);
}
void *run(void *vptr)
{
printf("Thread: %d got message %s and running........\n\n",
((struct info*)vptr)->no,((struct info*)vptr)->msg);
7/29/2019 C the SEA by Narendra
http://slidepdf.com/reader/full/c-the-sea-by-narendra 13/13
sleep(2);
strcpy(((struct info*)vptr)->msg,"Bye! Thanks for CPU time");
pthread_exit(0);
}
8) write a program in c which prints boot-sector (DOS or UNIX)?
9) Write a C-program for ‘Fibonacci-search’ implemataion10) Write equivalent Assembly instructions for i++ and i=i+1
(I is int).And which operation is faster.
Section 0x0005 TOUGH
1)Write steps required to compile a RPC program. Note : No need of writing total code
2) write C-code to allocate memory for 4-Dimentional integer
array(say arr[m][n][x][y]) using calloc() and free it using free()
3)Write small C-program to eject CD-ROM/RW or DVD-ROM/RW
drive?
4) How can u convert C-code into pure binary code? Writecompilation steps?
Note: You can use any compiler