main()
{
const char *fun();
*fun()='A';
} const char *fun()
{
return "Hello";
}
Ans. fun() returns to a "const char" pointer which cannot be modified
2. What would be the output of the following program?
main()
{
const int x=5; int *ptrx; ptrx=&x; *ptrx=10; printf("%d",x); }
a) 5 b) 10 c) Error d) Garbage value
3. A switch statement cannot include
a) constants as arguments b) constant expression as arguments
c) string as an argument d) None of the above
4. How long the following program will run?
main()
{
printf("\nSonata Software"); main(); }
a) infinite loop b) until the stack overflows
c) All of the above d) None of the above
5. On combining …show more content…
The program is trying to collect the value of a "void" function into an integer variable.
7. In the following program how would you print 50 using p?
main()
{
int a[]={10, 20, 30, 40, 50}; char *p; p= (char*) a;
}
Ans. printf("\n%d",*((int*)p+4));
8. Would the following program compile?
main()
{
int …show more content…
If the following program (myprog) is run from the command line as myprog 1 2 3, What would be the output?
main(int argc, char *argv[])
{
int i,j=0; for(i=0;i<argc;i++) j=j+ atoi(argv[i]); printf("%d",j); }
a) 1 2 3 b) 6 c) error d) "123"
13. If the following program (myprog) is run from the command line as myprog monday tuesday wednesday thursday? What would be the output?
main(int argc, char *argv[])
{
while(--argc >0) printf("%s",*++argv); }
a) myprog monday tuesday wednesday thursday b) monday tuesday wednesday thursday
c) myprog tuesday thursday d) None of the above
14. In the following code, is p2 an integer or an integer pointer?
typedef int* ptr ptr p1,p2;
Ans. Integer pointer
15. If the following program (myprog) is run from the command line as myprog friday tuesday sunday, What would be the output?
main(int argc, char *argv[])
{
while(sizeofargv) printf("%s",argv[--sizeofargv]); }
a) myprog friday tuesday sunday b) myprog friday tuesday
c) sunday tuesday friday myprog d) sunday tuesday friday
16. What would be the output of the following program?
main()
{
int i=4;