C Programming Fundamentals
Test your knowledge of C programming language fundamentals including memory management, pointers, operators, preprocessor directives, and standard library functions.
Questions
What would be the output of the following program?
main()
{
char *str,*str1="I Love You";
str=malloc(strlen(str1));
strcpy(str,str1);
printf("%s",str);
free(str);
}
- free() fails
- I Love You
- malloc() fails
- strcpy() fails
The header file which includes stdarg.h is_____________
- assert.h
- dos.h
- stdio.h
- mem.h
What are the types of variable f2 and p2 in the following declaration?
#define floatptr float *
#define int * intptr
floatptr f1,f2;
intptr p1,p2;
- float, int pointer
- float pointer, int pointer
- float, int
- float pointer, int
_______________ is a direct interface to the DOS call 0x44.
- ioctl
- ios
- dup
- tell
chmod() function is defined in which header file?
- assert.h
- dos.h
- io.h
- mem.h
What would be the output of the following?
void main()
{
int z,x=5,y=-10,a=4,b=2;
z=x++ - --y *b/a;
printf("%d",z);
}
- 5
- 12
- 10
- 11
In C, what is the difference between a declaration and definition of a variable?
- Both can occur multiple times, but a declaration must occur first.
- Both can occur multiple times, but a definition must occur first.
- A definition occurs once, but declaration may occur many times.
- A declaration occurs once, but definition may occur many times.
struct node *nptr,*sptr; /pointers for linked list/
for(nptr=sptr;nptr;nptr=nptr->next)
{
free(nptr);
}
- It will work correctly since the for loop covers the entire list.
- It may fail since each node “nptr” is freed before its next address can be accessed.
- This is invalid syntax for freeing memory.
- The loop will never end.
sizeof is an ________________
- int
- unsigned int
- long int
- anyone of the above
What would be the output of the following?
char *fun(char *ptr)
{
ptr+=3;
return(ptr);
}
void main()
{
char *x,*y;
x="Hello";
y=fun(x);
printf("%s",y);
}
- Hello
- lo
- llo
- Error
. and -> are __________ operators.
- binary
- unary
- ternary
- none of the above
What would be the output of the following?
void main()
{
int a=10,b;
b=a++ + ++a;
printf("%d %d %d %d",b,a++,a,++a);
}
- 22 10 11 13
- 22 11 11 11
- 22 10 11 13
- 22 13 13 13
The longjmp cannot pass the value
- -1
- 0
- 1
- 2
What would be the output of the following?
main()
{
int i=strlen("Blue")+strlen("Purple")/strlen("Red")-strlen("Green");
printf("%d",i);
}
- 0
- 3
- 2
- 1
What would be the output of the following?
main()
{
int val1=1234;
int val2=01234;
printf(%d %d,val1,val2);
}
- 1234 1234
- 1234 01234
- 1234 668
- 1234 688
The scope of a global variable which is declared as __________ is within the file.
- static
- extern
- register
- function argument
What would be the output of the following?
main()
{
int i,j;
for(i=0;;i++)
for(j=0;;j++)
if(j>100) break;
printf("%d%d",i,j);
}
- System Hangs
- 100 100
- 0 100
- 1 100
What would be the output of the following?
main()
{
int y,x=5;
y=++x - ++x;
printf("%d%d",x,y);
}
- 7 1
- 7 -1
- 7 0
- 5 1
What would be the output of the following?
void main()
{
int a=10,b;
b=a++ + ++a;
printf("%d %d %d %d",b,a++,a,++a);
}What would be the output of the following?
void main()
{
int i=7;
printf("%old %old %old %old",i,i++,i--,i++);
getch();
}
- old old old old
- 7ld 8ld 7ld 8ld
- 10ld 7ld 10ld 7ld
- Error