IndiaBIX.com
Arithmetic Aptitude Data Interpretation
Logical Reasoning Verbal Reasoning Non Verbal Reasoning
General Knowledge
Sudoku Number puzzles Missing letters puzzles Logical puzzles Playing cards puzzles Clock puzzles
C Programming C++ Programming C# Programming Java Programming
Microbiology Biochemistry Biotechnology Biochemical Engineering
Civil Engineering Mechanical Engineering Chemical Engineering Networking Database Questions Computer Science Basic Electronics Digital Electronics Electronic Devices Circuit Simulation Electrical Enigneering Engineering Mechanics Technical Drawing
Placement Papers Group Disucssion HR Interview Technical Interview Body Language
Aptitude Test Verbal Ability Test Verbal Reasoning Test Logical Reasoning Test C Programming Test Java Programming Test Data Interpretation Test General Knowledge Test
Data Structures Operating Systems Networking DATABASE Database Basics SQL Server Basics SQL Server Advanced SQL Server 2008 JAVA Core Java Java Basics Advanced Java UNIX Unix File Management Unix Memory Management Unix Process Managemnt C Interview Questions The C Language Basics .NET Interview Questions .NET Framework ADO.NET ASP.NET Software Testing

C Programming - Pointers - Discussion

@ : Home > C Programming > Pointers > Yes / No Questions - Discussion

Read more:

"Two things are infinite: the universe and human stupidity; and I'm not sure about the universe."
- Albert Einstein
4. 

Will the program compile in Turbo C?

#include<stdio.h>
int main()
{
    int a=10, *j;
    void *k;
    j=k=&a;
    j++;
    k++;
    printf("%u %u\n", j, k);
    return 0;
}

[A]. Yes[B]. No

Answer: Option E

Explanation:

Error in statement k++. We cannot perform arithmetic on void pointers.

The following error will be displayed while compiling above program in TurboC.

Compiling PROGRAM.C:
Error PROGRAM.C 8: Size of the type is unknown or zero.


Ankit Anand said: (Fri, Jun 25, 2010 03:00:50 PM)    
 
printf statement should be:-

printf("%u %u\n", *j, *((int *)k));

else everything fine on LINUX

Andras Joo said: (Fri, Oct 1, 2010 09:11:27 AM)    
 
In practice some compilers treat void pointers as unsigned char pointers.

void * p = 0;
++p;
printf("%u\n", p);

The output will be 1, if compiled with GCC.

Manoj said: (Fri, Sep 9, 2011 03:57:40 PM)    
 
If GCC compiler increments by 1 ,then how it is decided or depends on???

If ++ is used on int pointer then it gets incremented by 4 because int is of size 4 but then what is the size of void???

Rupinder said: (Wed, Nov 30, 2011 03:21:51 AM)    
 
If your code output is unexpected and there is no logical and syntactical error and reason for that unexpected output is compiler design,then your code is poorly written.

Megala said: (Fri, Dec 23, 2011 10:30:57 PM)    
 
I think the statement
j=k=&a;
is wrong

It will generate compiler error.

Sam said: (Fri, Jan 20, 2012 03:43:07 AM)    
 
It will be compiled. As it should display the memory locations next to the location of a.

Manish said: (Sat, Feb 18, 2012 11:57:28 PM)    
 
The void pointer can't perform arithmetic operation.

Vishu said: (Tue, Apr 24, 2012 04:27:46 PM)    
 
There are no errors in the above program. I compiled and I got the output.

Write your comments here:
Name *:     Email:


© 2008-2013 by IndiaBIX™ Technologies. All Rights Reserved | Copyright | Terms of Use & Privacy Policy

Contact us: info@indiabix.com     Follow us on twitter!