Showing posts with label return. Show all posts
Showing posts with label return. Show all posts

Thursday, December 20, 2012

What happen if we have 2 return statement in a function

//Program in cpp using 2 return statement in function
#include <iostream>
using namespace std;

int add ()
{
    return 2;
    return 3;
}

int main()
{
    cout << add();
}
  • If  we compiler this program using GCC compiler, it would not give any error or warning.
  • But when we compile this program in Dotnet it give warning message.
___________________________________________________________________________________
//Program in sql using 2 return statement in function
create function ab()
returns int
as
    begin
        return 100
        return 120
    end
   
print dbo.ab()

This is not give the error because the sql compiler is not enough smart

MORAL of the story: it totally dependent on the compiler, that it gives warning or not, when we use 2 return statement in a function.

Wednesday, October 17, 2012

What is the retrun-type of printf

About printf:    
printf is the formatted print routine that comes as part of the standard C library. the first argument to print is a format string. it describes how any remaining argument are to be printed. The charater % begins a print specification for an argument. In our program, %d told printf to interpret and print the next argument as a decimal number. printf can also output literal characters. In our program, we "printed" a newline character by giving its name (\n) in the format string. 
-----------------------------------------------------------------------------------------------
#include <stdio.h>

int main()
{
    int a = 57;
    printf ("\n");
   
    //What is the output of this

    printf ("%d ");    // This gives garbage value
    printf ("\n\n");    //this is used only to get clear output
   
    //What is the output of this
    printf ("%d",printf("%d",56));  //without space
    printf ("\n\n");
   
    //What is the output of this

    printf ("%d",printf("%d ",56));
    printf ("\n\n");
   
    //What is the output of this
    printf ("%d",printf("%d ",a));
    printf ("\n\n");
   
    //What is the output of this
    printf("%d ",printf("%d ",printf("%d ",56))); //that's very interesting
    printf ("\n\n");
   
    //What is the output of this
    printf ("%d \t %d ",58, a);               // 'space' -->takes 1 character
    printf ("\n\n");
   
    //What is the output of this
    printf("%d",printf ("%d \t %d ",58, a));  // \t -->takes 1 character
    printf ("\n\n");
   
    //What is the output of this
    printf("%d",printf ("%d\n\t %d ",a,59));  // \n -->takes 1 character
    printf ("\n");
   
    return 0;
}


OUTPUT: