C Programming Fundamentals

Test your knowledge of C programming language fundamentals including memory management, pointers, operators, preprocessor directives, and standard library functions.

19 Questions Published

Questions

Question 1 Multiple Choice (Single Answer)

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);
}

  1. free() fails
  2. I Love You
  3. malloc() fails
  4. strcpy() fails
Question 2 Multiple Choice (Single Answer)

The header file which includes stdarg.h is_____________

  1. assert.h
  2. dos.h
  3. stdio.h
  4. mem.h
Question 3 Multiple Choice (Single Answer)

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;

  1. float, int pointer
  2. float pointer, int pointer
  3. float, int
  4. float pointer, int
Question 4 Multiple Choice (Single Answer)

_______________ is a direct interface to the DOS call 0x44.

  1. ioctl
  2. ios
  3. dup
  4. tell
Question 5 Multiple Choice (Single Answer)

chmod() function is defined in which header file?

  1. assert.h
  2. dos.h
  3. io.h
  4. mem.h
Question 6 Multiple Choice (Single Answer)

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);
}

  1. 5
  2. 12
  3. 10
  4. 11
Question 7 Multiple Choice (Single Answer)

In C, what is the difference between a declaration and definition of a variable?

  1. Both can occur multiple times, but a declaration must occur first.
  2. Both can occur multiple times, but a definition must occur first.
  3. A definition occurs once, but declaration may occur many times.
  4. A declaration occurs once, but definition may occur many times.
Question 8 Multiple Choice (Single Answer)

struct node *nptr,*sptr; /pointers for linked list/
for(nptr=sptr;nptr;nptr=nptr->next)
{
free(nptr);
}

Releases memory from a linked list. Which of the following accurately describes how it will work?

  1. It will work correctly since the for loop covers the entire list.
  2. It may fail since each node “nptr” is freed before its next address can be accessed.
  3. This is invalid syntax for freeing memory.
  4. The loop will never end.
Question 9 Multiple Choice (Single Answer)

sizeof is an ________________

  1. int
  2. unsigned int
  3. long int
  4. anyone of the above
Question 10 Multiple Choice (Single Answer)

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);
}

  1. Hello
  2. lo
  3. llo
  4. Error
Question 11 Multiple Choice (Single Answer)

. and -> are __________ operators.

  1. binary
  2. unary
  3. ternary
  4. none of the above
Question 12 Multiple Choice (Single Answer)

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);
}

  1. 22 10 11 13
  2. 22 11 11 11
  3. 22 10 11 13
  4. 22 13 13 13
Question 13 Multiple Choice (Single Answer)

The longjmp cannot pass the value

  1. -1
  2. 0
  3. 1
  4. 2
Question 14 Multiple Choice (Single Answer)

What would be the output of the following?

main()
{
int i=strlen("Blue")+strlen("Purple")/strlen("Red")-strlen("Green");
printf("%d",i);
}

  1. 0
  2. 3
  3. 2
  4. 1
Question 15 Multiple Choice (Single Answer)

What would be the output of the following?

main()
{
int val1=1234;
int val2=01234;
printf(%d %d,val1,val2);
}

  1. 1234 1234
  2. 1234 01234
  3. 1234 668
  4. 1234 688
Question 16 Multiple Choice (Single Answer)

The scope of a global variable which is declared as __________ is within the file.

  1. static
  2. extern
  3. register
  4. function argument
Question 17 Multiple Choice (Single Answer)

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);
}

  1. System Hangs
  2. 100 100
  3. 0 100
  4. 1 100
Question 18 Multiple Choice (Single Answer)

What would be the output of the following?

main()
{
int y,x=5;
y=++x - ++x;
printf("%d%d",x,y);
}

  1. 7 1
  2. 7 -1
  3. 7 0
  4. 5 1
Question 19 Multiple Choice (Single Answer)

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();
}

  1. old old old old
  2. 7ld 8ld 7ld 8ld
  3. 10ld 7ld 10ld 7ld
  4. Error