OOPs, Assignment # 1 - Prof. KR Chowdhary, Ph.D.

advertisement
OOPs, Assignment # 1
BE: CSE/IT-III Semester
September 2, 2012
Submission deadline: 13th Sept. 2012
1. Answer the following question in brief, but logically and completely:
(a) How do you write a program which produces its own source code as its output?
(b) How can you find the day of the week given the date?
(c) Why does not C have nested functions?
(d) Suggest an algorithm to convert integers to binary or hexadecimal?
(e) How you access command-line arguments?
(f) How can you return multiple values from a function?
(g) How can you invoke another program from within a C program?
(h) How can you access memory located at a certain address?
(i) How can you allocate arrays or structures bigger than 64K?
(j) How can you find out how much memory is available?
(k) How can you read a directory in a C program?
2. The expected output of the following C program is to print the elements in the array. But when
actually run, it does not do so. Find out what is going wring?
#include<stdio.h>
#define TOTELEM(sizeof(array) / sizeof(array[0]))
int array[] = {23,34,12,17,204,99,16};
int main(){
int d;
for(d=-1;d <= (TOTELEM-2);d++)
printf("%d\n",array[d+1]);
return 0;
}
3. What is the expected output for the following program and why?
enum {false,true};
int main()
int i=1;
do
{
printf("%d\n",i);
i++;
if(i < 15)
continue;
1
}while(false);
return 0;
}
4. The following program does not appear to print “hello-out”. (Try executing it, and give the reason).
#include <stdio.h>
#include <unistd.h>
int main()
{
while(1)
{
fprintf(stdout,"hello-out");
fprintf(stderr,"hello-err");
sleep(1);
}
return 0;
}
5. What is the difference between the following function calls to scanf ?(Notice the space carefully in
the second call. Try removing it and observe the behaviour of the program)
#include <stdio.h>
int main()
{
char c;
scanf("%c",&c);
printf("%c\n",c);
scanf(" %c",&c);
printf("%c\n",c);
return 0;
}
6. What is the output of the following program?
#include <stdio.h>
int main()
{
int i = 6;
if( ((++i < 7) && ( i++/6)) || (++i <= 9))
;
printf("%d\n",i);
return 0;
}
Note: The homework should be done in a book of A-4 size plain papers (without any print out). Write your
roll no. name, class on first page top, and page number on each. The work should be clean, if there is any
deletion/crossing, use a new page. All the pages should be stapled / properly pinned, and put under an file
cover. Important: Late submission will not be accepted in any circumstances.
2
Download