C Pointers - Aptitude Questions & Answers

C programming Pointers Aptitude Questions and Answers: In this section you will find C Aptitude Questions and Answers on Pointers topics, declaring pointers, using pointers, pointer with other c topics like pointer of array etc.

1) What will be the output of following program ?
#include <stdio.h>
int main()
{
	char	*str="IncludeHelp";
	printf("%c\n",*&*str);
	return 0;
}
  1. Error
  2. IncludeHelp
  3. I
  4. *I

2) What will be the output of following program ?
#include <stdio.h>
int main()
{
	int		iVal;
	char	cVal;
	void	*ptr;	// void pointer
	iVal=50; cVal=65;

	ptr=&iVal;
	printf("value =%d,size= %d\n",*(int*)ptr,sizeof(ptr));
	
	ptr=&cVal;
	printf("value =%d,size= %d\n",*(char*)ptr,sizeof(ptr));
	return 0;
}
  1. Error
  2. value =50,size= 4
    value =65,size= 4
  3. value =50,size= 4
    value =65,size= 1
  4. Garbage Values


3) What will be the output of following program ?
#include <stdio.h>
int main()
{
	char	*str	[]={"AAAAA","BBBBB","CCCCC","DDDDD"};
	char	**sptr	[]={str+3,str+2,str+1,str};
	char	***pp;

	pp=sptr;
	++pp;
	printf("%s",**++pp+2);
	return 0;
}
  1. BBBBB
  2. CCCCC
  3. BBB
  4. Error

4) What will be the output of following program ?
#include <stdio.h>
char* strFun(void)
{
	char *str="IncludeHelp";
	return str;
}
int main()
{
	char *x; 
	x=strFun();
	printf("str value = %s",x);
	return 0;
}
  1. str value = Garbage value
  2. str value = IncludeHelp
  3. Error
  4. No output


5) If the address of pointer ptr is 2000, then what will the output of following program ?
[On 32 bit compiler.]
#include <stdio.h>
int main()
{
	void *ptr;
	++ptr;
	printf("%u",ptr);
    return 0;
}
  1. 2004
  2. 2001
  3. 2000
  4. ERROR

6) What will be the output of following program ?
#include <stdio.h>
int main()
{
	char ch=10;
	void *ptr=&ch;
	printf("%d,%d",*(char*)ptr,++(*(char*)ptr));
	return 0;
}
  1. 11,11
  2. 10,11
  3. ERROR
  4. 10,10

7) What will be the output of following program ?
#include <stdio.h>
int main()
{
	int a=10,b=2;
	int *pa=&a,*pb=&b;
	printf("value = %d", *pa/*pb);
	return 0;
}
  1. 5
  2. 5.0
  3. ERROR
  4. None of these

8) What will be the output of following program ?
#include <stdio.h>
void fun(int *ptr)
{
	*ptr=100;
}
int main()
{
	int num=50;
	int *pp=#
	fun(& *pp);
	printf("%d,%d",num,*pp);
	return 0;
}
  1. 100,100
  2. 50,50
  3. 50,100
  4. ERROR in function calling






Comments and Discussions!

Load comments ↻






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