C Functions and Blocks - Aptitude Questions & Answers

C programming Functions and Blocks Aptitude Questions and Answers: In this section you will find C Aptitude Questions and Answers on Functions and Blocks – Scope of the block, function’s declarations, function’s definition, function’s calling etc.

1) What will be the output of following program ?
#include <stdio.h>
int main()
{
	int var=100;
	{
		int var=200;
		printf("%d...",var);
	}
	printf("%d",var);
	return 0;
}
  1. ERROR
  2. 200...200
  3. 100...100
  4. 200...100

2) What will be the output of following program ?
#include <stdio.h>
char* fun1(void)
{
	char str[]="Hello";
	return str;
}

char* fun2(void)
{
	char *str="Hello";
	return str;
}
int main()
{
	printf("%s,%s",fun1(),fun2());
	return 0;
}
  1. ERROR
  2. Hello,Hello
  3. Hello,Garbage
  4. Garbage,Hello

3) What will be the output of following program ?
#include <stdio.h>

int fooo(void)
{
	static int num=0;
	num++;
	return num;
}
int main()
{
	int val;
	val=fooo();
	printf("step1: %d\n",val);
	val=fooo();
	printf("step2: %d\n",val);
	val=fooo();
	printf("step3: %d\n",val);
	return 0;
}
  1. step1: 1
    step2: 1
    step3: 1
  2. step1: 1
    step2: 2
    step3: 3
  3. step1: 0
    step2: 0
    step3: 0
  4. ERROR

4) What will be the output of following program ?
#include <stdio.h>

int main()
{
	int anyVar=10;
	printf("%d",10);
	return 0;
}
extern int anyVar;
  1. Compile time error
  2. 10
  3. Run time error
  4. None of these





Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.