GeekInterview.com
   Home |  Tech FAQ  |   Interview Questions |  Placement Papers |  Tech Articles |  Learn |  Freelance Projects |  Online Testing |  Geeks Talk |  Job Postings |  Knowledge Base | Site Search |  Add/Ask Question

GeekInterview.com  >  Interview Questions  >  Programming  >  C
Go To First  |  Previous Question  |  Next Question 
 C  |  Question 422 of 433    Print  
printf() and printf as a variable
can printf be used as a variable as well as a procedure?


  
Total Answers and Comments: 2 Last Update: July 19, 2008     Asked by: chandrikakr 
  
 Sponsored Links

 
 Best Rated Answer
Submitted by: Jaya_Kaja
 

printf  can be used as a variable . But once we declare a variable printf ,
standard Library function "printf"  can not be recongnized by the compiler within   the scope of the variable  (reason :local symbol might be having higher precedence ).
If at all library func is  used ,compiler  wil throw the error saying- " called object is not a function."

For eg : below  is an  error free C program :

#include <stdio.h>
int main()

{
     int printf;
     printf = 10;
  /*  printf("n My Number = %d",num);*/  /* Activating this line,causes an error */
     Display( printf);
    return 1;
}

Display(int num)
{
    printf("n My Number = %d",num);
}

Note : But in programming it is not recommended to  use the sandard symbols.



-Jayalakshmi  Kaja
 



Above answer was rated as good by the following members:
kmcanil, sourabh_t
July 14, 2008 17:06:49   #1  
janhavibend Member Since: July 2008   Contribution: 5    

RE: printf() and printf as a variable
printf can't be used as a variable name. Printf is a library function and When you are trying to use printf variable compiler will give an error like "called object 'printf' is not a function"
 
Is this answer useful? Yes | NoAnswer is useful 0   Answer is not useful 1Overall Rating: -1    
July 18, 2008 12:41:13   #2  
Jaya_Kaja Member Since: July 2008   Contribution: 2    

RE: printf() and printf as a variable

printf  can be used as a variable . But once we declare a variable printf ,
standard Library function "printf"  can not be recongnized by the compiler within   the scope of the variable  (reason :local symbol might be having higher precedence ).
If at all library func is  used ,compiler  wil throw the error saying- " called object is not a function."

For eg : below  is an  error free C program :

#include <stdio.h>
int main()

{
     int printf;
     printf = 10;
  /*  printf("n My Number = %d",num);*/  /* Activating this line,causes an error */
     Display( printf);
    return 1;
}

Display(int num)
{
    printf("n My Number = %d",num);
}

Note : But in programming it is not recommended to  use the sandard symbols.



-Jayalakshmi  Kaja
 


 
Is this answer useful? Yes | NoAnswer is useful 2   Answer is not useful 0Overall Rating: +2    

 Related Questions

  A switch statement is generally best to use when you have more than two conditional expressions based on a single variable of numeric type.  
Latest Answer : when we have only single  condition then switch is better.otherwise....... ...

An lvalue is an expression to which a value can be assigned. The lvalue expression is located on the left side of an assignment statement, whereas an rvalue is located on the right side of an assignment 
Latest Answer : lvalue is is a memory location,whose value is not constant i.e it's value is changed when a new value entered into that location.And also it can be say as, it is an expression,where  left side we have an identifier and right side(rvalue) the ...

An lvalue was defined as an expression to which a value can be assigned. Is an array an expression to which we can assign a value? The answer to this question is no, because an array is composed of several 
Latest Answer : I have a doubt. How about this statement:int a[] = {"1", "4", "6", "3"};It is definition and initialization but is also assignment for whole of array a. Isn's array a being treated here as an lvalue? ...

The register modifier hints to the compiler that the variable will be heavily used and should be kept in the CPU’s registers, if possible, so that it can be accessed faster. There are several restrictions 
Latest Answer : If a variable is defined by using register modifier it tells to the compiler that the variable is used repetedly and that variable executes fastly. Generally register variables are defined in loop counters. This variable stored in CPU registers and access ...

The volatile modifier is a directive to the compiler’s optimizer that operations involving this variable should not be optimized in certain ways. There are two special cases in which use of the 

Yes. The const modifier means that this code cannot change the value of the variable, but that does not mean that the value cannot be changed by means outside this code. For instance, in the example in  
Latest Answer : But isnt like the constant variables will be stored by in ROM (read only memory).Then how can the some process other than the code can change the value of const volatile ...

For integral types, on a machine that uses two’s complement arithmetic (which is just about any machine you’re likely to use), a signed type can hold numbers from –2(number of bits – 
Latest Answer : Hi,a simple code snipet show how to determin the maximum value that an integer can  haveunsigned int x = 0;--x;now check the  value of x. This would contain maximum value that an interger can have.now you can determine the values containing ...

A global variable that must be accessed from more than one file can and should be declared in a header file. In addition, such a variable must be defined in one source file. Variables should not be defined 
Latest Answer : A variable can be declare/define in a C Header without any kind of compilational/ logical errors. But it is against the coding specifications and it is not normally practiced. If proper Multiple inclusion protection macro is used, then there will be no ...

Declaring a variable means describing its type to the compiler but not allocating any space for it. Defining a variable means declaring it and also allocating space to hold the variable. You can also 
Latest Answer : int num;This statement is declaration and also defination since it also allocates memory for variable num.But when you use following statementextern int num;It is only declaration since you are not allocating memory here. ...

You can’t declare a static variable without defining it as well (this is because the storage class modifiers static and extern are mutually exclusive). A static variable can be defined in a header 
Latest Answer : In CThe scope of static variable is file. ie., if declared the variable is accessible accross the file.When declared the vairable in a header then its exposed to where ever its included.  Every file will have a local copy.  You need to extern ...


 Sponsored Links

 
Related Articles

Concepts of Object-Oriented Programming

Object Oriented JavaScript In this chapter you ll learn about OOP Object Oriented Programming and how it relates to JavaScript As an ASP NET developer you probably have some experience working with objects and you may even be familiar with concepts such as inheritance However unless you re already a
 

printf() Function Return Value

What is the return value from printf() function? printf function always returns the number of characters printed. Let us understand this with an example: main() { int a=10; printf(&quot;%d&quot;,printf(&quot;%d %d %d&quot;, a,a,a)); } In this above program the inner printf i
 

What happens when a variable is not initialized in main function?

When a variable is not initialized in main function it contains garbage value. This can be well seen from the example below main() { int x; printf(&ldquo;%d&rdquo;,x); z= sample() } sample() { printf(&ldquo;Testing program&rdquo;); } Output is &nbsp;&nbsp;&n
 

What happens when a variable is not declared in function definition?

Generally in C program the function definition and calling takes the form as given below: main() { int x,y,z; z=sample(x,y); printf(&ldquo;%d&rdquo;,z); } sample(x1,y1) int x1,y1; { int z1; z1= x1 - y1; return(z1); } Here what happens is the values x, y gets passed to x1,y1
 

What are the Format Specifiers used with printf?

There are several format specifiers available in printf. The format specifier used varies depending on the data type used for printing. The given below are some of the format specifiers used with printf in C program. For integer data type the format specifier used with printf is %d or %i For float
 

printf and sprintf

What is the difference between printf and sprintf? sprintf: Writes formatted data to a character string in memory instead of stdout Syntax of sprintf is: #include &lt;stdio.h&gt; int sprintf (char *string, const char *format [,item [,item]...]); Here, String refers to the pointer to a
 

SQL Programming

SQL Programming Overview Anybody who has done something for a long time has probably wanted to change how things work at some point or another. A worker at a mill might have found a more efficient way of cutting logs, or a mathematics teacher might have had a hand in changing a school&rsquo;s al
 

The Interview Snafu

How to turn someone else&rsquo;s mistake to your advantage Your dream job is about to become reality. A recruiter gave you the heads up about the perfect position at Humungous Conglomerate, Inc. You went through five interviews as well as a battery of psychological tests mandated by their HR de
 

Winning a Job Interview with a Winning Resume

Does your resume unlock your potential, take your skills to the highest level and win you the interview and the job you want now? The job market today is highly competitive and even if you think you have what it takes to get an interview you won&rsquo;t get over the line without a polished, prof
 

WinRunner Programming Concepts

If you want to create WinRunner scripts that are highly efficient, there are important programming concepts that you will want to become familiar with. Understanding these concepts will provide you with a large number of key benefits. In addition to understanding these concepts, you must also learn
 





About Us  |   Privacy Policy  |   Terms and Conditions  |   Contact  |   Site Map  |   Add Question  |   Propose Category  |   RSS Feeds  |   Articles Sitemap  |   Site Updates  |   Add Resource

Copyright © 2005 - 2008 GeekInterview.com. All Rights Reserved
Page copy protected against web site content infringement by Copyscape