Author Topic: C programming problems  (Read 3810 times)

0 Members and 1 Guest are viewing this topic.

Offline RAYAN FOSTER

  • Universal Moderator
  • Super Member
  • *
  • Points: 1742
  • Posts: 1039

    • BVP
    • _
      ECE
    • View Profile
C programming problems
« on: May 15, 2015, 11:40:55 pm »
WAP to print "Hello" without using a semicolon?

Koi iska answer btaega with reason!!
You do not have permission to give points
point 10 Points

Users who gave points in this topic » sagrma (10 Pts) 

Offline EZIO

  • Universal Moderator
  • Super Member
  • *
  • Points: 4683
  • Posts: 1187
  • My Enemy is a NOTION not a NATION

    • MSIT
    • _
      CSE
    • View Profile
Re: C programming problems
« Reply #1 on: May 16, 2015, 11:47:10 am »

Code:
Only registered users can see contents. Please click here to Register or Login.printf and scanf returns number of characters printed
so in this case printf will return 5
so your if statement will become
if(5)    //hello have 5 characters


this will return true and control will move to if block
since there is nothing to executes
the program terminates successfully


to check that printf return number of characters printed
heres a program
Code:
Only registered users can see contents. Please click here to Register or Login.output will be 5


IF YOU FIND MY LINKS NOT WORKING. PM ME OR POST A REQUEST ON THE THREAD!!

Offline RAYAN FOSTER

  • Universal Moderator
  • Super Member
  • *
  • Points: 1742
  • Posts: 1039

    • BVP
    • _
      ECE
    • View Profile
Re: C programming problems
« Reply #2 on: May 16, 2015, 12:35:31 pm »
Code:
Only registered users can see contents. Please click here to Register or Login.printf and scanf returns number of characters printed
so in this case printf will return 5
so your if statement will become
if(5)    //hello have 5 characters


this will return true and control will move to if block
since there is nothing to executes
the program terminates successfully


to check that printf return number of characters printed
heres a program
Code:
Only registered users can see contents. Please click here to Register or Login.output will be 5
if (5)
yaha tk samaj aaya lekin wo hello kyu print karega??

Offline EZIO

  • Universal Moderator
  • Super Member
  • *
  • Points: 4683
  • Posts: 1187
  • My Enemy is a NOTION not a NATION

    • MSIT
    • _
      CSE
    • View Profile
Re: C programming problems
« Reply #3 on: May 16, 2015, 04:08:51 pm »
**Considering you know basic programming and have knowledge about functions**


supposed you have a function named value defined as follows
Code:
Only registered users can see contents. Please click here to Register or Login.now try to call this in the main function
Code:
Only registered users can see contents. Please click here to Register or Login.in the if block, the control first moves to check the condition
there it will encounter the function call value so the control will move to value()
no matter what the code is "whatever is inside the value function will be executed first"


SO similarly printf is also a function
when you call it in the if's condition
it executes its function i.e prints the value to the console output
and then the control moves back to the main function
if checks the condition
and further codes are executed


IF YOU FIND MY LINKS NOT WORKING. PM ME OR POST A REQUEST ON THE THREAD!!

Offline RAYAN FOSTER

  • Universal Moderator
  • Super Member
  • *
  • Points: 1742
  • Posts: 1039

    • BVP
    • _
      ECE
    • View Profile
Re: C programming problems
« Reply #4 on: May 16, 2015, 07:25:41 pm »
**Considering you know basic programming and have knowledge about functions**


supposed you have a function named value defined as follows
Code:
Only registered users can see contents. Please click here to Register or Login.now try to call this in the main function
Code:
Only registered users can see contents. Please click here to Register or Login.in the if block, the control first moves to check the condition
there it will encounter the function call value so the control will move to value()
no matter what the code is "whatever is inside the value function will be executed first"


SO similarly printf is also a function
when you call it in the if's condition
it executes its function i.e prints the value to the console output
and then the control moves back to the main function
if checks the condition
and further codes are executed
ok I got you ^_^
Thanxs for helping :)
btw you used semicolon in the return statement  ;-)

Offline EZIO

  • Universal Moderator
  • Super Member
  • *
  • Points: 4683
  • Posts: 1187
  • My Enemy is a NOTION not a NATION

    • MSIT
    • _
      CSE
    • View Profile
Re: C programming problems
« Reply #5 on: May 16, 2015, 07:41:06 pm »
we use semicolon after return @RAYAN FOSTER


IF YOU FIND MY LINKS NOT WORKING. PM ME OR POST A REQUEST ON THE THREAD!!

Offline RAYAN FOSTER

  • Universal Moderator
  • Super Member
  • *
  • Points: 1742
  • Posts: 1039

    • BVP
    • _
      ECE
    • View Profile
Re: C programming problems
« Reply #6 on: May 16, 2015, 10:16:35 pm »
we use semicolon after return @RAYAN FOSTER
I know ki hm semicolon lagate h..lekin question to mana kr rha h!!

Offline EZIO

  • Universal Moderator
  • Super Member
  • *
  • Points: 4683
  • Posts: 1187
  • My Enemy is a NOTION not a NATION

    • MSIT
    • _
      CSE
    • View Profile
Re: C programming problems
« Reply #7 on: May 16, 2015, 10:34:13 pm »
Use void main
Gcc ki aadat hai mjhe :S


IF YOU FIND MY LINKS NOT WORKING. PM ME OR POST A REQUEST ON THE THREAD!!

Offline Sam

  • I am what I am
  • Universal Moderator
  • Super Member
  • *
  • Points: 2616
  • Posts: 1316
  • I am what I am

    • NIEC
    • _
      CSE
    • View Profile
    • TheGeekyWay- Free tutorials on Programming, WebDevelopment, Electronics, Linux etc.
Re: C programming problems
« Reply #8 on: May 16, 2015, 10:37:01 pm »
If you want then take void main() instead of int main() but that's not actually correct according to C standards.

But your problem will be done without using semi-colon. BDW, there is no real use of code, just good to know.

But who cares, it's IPU, and what everyone care here is just about printing Hello World without semicolon  8-) and teaching nothing in applicability.


Offline EZIO

  • Universal Moderator
  • Super Member
  • *
  • Points: 4683
  • Posts: 1187
  • My Enemy is a NOTION not a NATION

    • MSIT
    • _
      CSE
    • View Profile
Re: C programming problems
« Reply #9 on: May 16, 2015, 10:43:48 pm »
Exactly @Sam
Programming here is just about printing hello world  (:|


IF YOU FIND MY LINKS NOT WORKING. PM ME OR POST A REQUEST ON THE THREAD!!

Offline RAYAN FOSTER

  • Universal Moderator
  • Super Member
  • *
  • Points: 1742
  • Posts: 1039

    • BVP
    • _
      ECE
    • View Profile
Re: C programming problems
« Reply #10 on: May 16, 2015, 10:52:46 pm »
If you want then take void main() instead of int main() but that's not actually correct according to C standard
why it is not correct according to C?

jst because..function should return a value!!
« Last Edit: May 16, 2015, 10:54:26 pm by RAYAN FOSTER »

Offline The Dark Knight

  • Moderator
  • Super Member
  • *
  • Points: 1380
  • Posts: 879

    • MSIT
    • _
      CSE
    • View Profile
Re: C programming problems
« Reply #11 on: May 16, 2015, 11:57:47 pm »

Code:
Only registered users can see contents. Please click here to Register or Login.printf and scanf returns number of characters printed
so in this case printf will return 5
so your if statement will become
if(5)    //hello have 5 characters


this will return true and control will move to if block
since there is nothing to executes
the program terminates successfully


to check that printf return number of characters printed
heres a program
Code:
Only registered users can see contents. Please click here to Register or Login.output will be 5
in the solution, there is usage of semi-colon so...........

Offline EZIO

  • Universal Moderator
  • Super Member
  • *
  • Points: 4683
  • Posts: 1187
  • My Enemy is a NOTION not a NATION

    • MSIT
    • _
      CSE
    • View Profile
Re: C programming problems
« Reply #12 on: May 17, 2015, 08:27:54 am »
Code:
Only registered users can see contents. Please click here to Register or Login.*GCC Compiler*
OR
Code:
Only registered users can see contents. Please click here to Register or Login.*Turbo C*


IF YOU FIND MY LINKS NOT WORKING. PM ME OR POST A REQUEST ON THE THREAD!!

Offline The Dark Knight

  • Moderator
  • Super Member
  • *
  • Points: 1380
  • Posts: 879

    • MSIT
    • _
      CSE
    • View Profile
Re: C programming problems
« Reply #13 on: May 17, 2015, 01:13:15 pm »
After int main(), there is a need for return statement or not ?


if we write return0 or return1,will it make any diff?

Offline EZIO

  • Universal Moderator
  • Super Member
  • *
  • Points: 4683
  • Posts: 1187
  • My Enemy is a NOTION not a NATION

    • MSIT
    • _
      CSE
    • View Profile
Re: C programming problems
« Reply #14 on: May 17, 2015, 02:21:12 pm »

Return statement for main depends on compiler
if your using gcc compiler then no matter whether you have written return statement or not
the compiler will implicitly return 0 for successful execution


return 1 or return 0 only tell the value which the main function is returning 


IF YOU FIND MY LINKS NOT WORKING. PM ME OR POST A REQUEST ON THE THREAD!!

 

DIRECT X game programming

Started by sarthak9333

Replies: 1
Views: 1248
Last post December 05, 2012, 03:06:32 pm
by SagarDabas
Programming Challenge!!!!

Started by kurosaki

Replies: 173
Views: 56063
Last post November 28, 2016, 11:42:01 pm
by swapnil7
improve your programming...!!!

Started by ab2757

Replies: 14
Views: 5532
Last post August 27, 2013, 08:14:34 pm
by cool98765
programming is frustrating!!

Started by slimshady

Replies: 6
Views: 2846
Last post January 22, 2010, 08:11:14 pm
by ANKITSINGHAL
regarding java programming

Started by Ratika

Replies: 4
Views: 2628
Last post May 14, 2015, 07:17:38 pm
by sagrma
Sitemap 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49