Skip to main content

Your First Program in c

Your First Program

Objectives:

Having read this section you should have an understanding of:

1.a preprocessor directive that must be present in all your C programs.
2.a simple C function used to write information to your screen.
3.how to add comments to your programs

Now that you've seen the compiler in action it's time for you to write your very own first C program. You can probably guess what it's going to be - the program that everyone writes just to

check they understand the very, very, very basics of what is going on in a new language.

Yes - it's the ubiquitous "Hello World" program. All your first program is going to do is print the message "Hello World" on the screen.

The program is a short one, to say the least. Here it is:


#include
main()
{

while(1==1) printf("Hello World\n");
}


The first line is the standard start for all C programs - main(). After this comes the program's only instruction enclosed in curly brackets {}. The curly brackets mark the start and end of the

list of instructions that make up the program - in this case just one instruction.

Notice the semicolon marking the end of the instruction. You might as well get into the habit of ending every C instruction with a semicolon - it will save you a lot of trouble! Also notice that
the semicolon marks the end of an instruction - it isn't a separator as is the custom in other languages.

If you're puzzled about why the curly brackets are on separate lines I'd better tell you that it's just a layout convention to help you spot matching brackets. C is very unfussy about the way

you lay it out. For example, you could enter the Hello World program as:

main(){printf("Hello World\n");}

but this is unusual.

The printf function does what its name suggest it does: it prints, on the screen, whatever you tell it to. The "\n" is a special symbols that forces a new line on the screen.

OK, that's enough explanation of our first program! Type it in and save it as Hello.c.Then use the compiler to compile it, then the linker to link it and finally run it. The output is as follows:

Hello World


Add Comments to a Program:

A comment is a note to yourself (or others) that you put into your souce code. All comments are ignored by the compiler. They exist solely for your benefit. Comments are used primarily to
document the meaning and purpose of your source code, so that you can remember later how it functions and how to use it. You can also use a comment to temporarily remove a line of
code. Simply surround the line(s) with the comment symbols.

In C, the start of a comment is signaled by the /* character pair. A comment is ended by */. For example, this is a syntactically correct C comment:

/* This is a comment. */

Comments can extend over several lines and can go anywhere except in the middle of any C keyword, function name or variable name. In C you can't have one comment within another
comment. That is comments may not be nested. Lets now look at our first program one last time but this time with comments:

main() /* main function heading */
{
printf("\n Hello, World! \n"); /* Display message on */
} /* the screen */

This program is not large enough to warrant comment statements but the principle is still the same.

Comments

Popular posts from this blog

6 Ways to Hack or deface Websites Online

Hello friends , today i will explain all the methods that are being used to hack a website or websites database. This is the first part of the hacking websites tutorial where i will explain in brief all methods for hacking or defacing websites. Today I will give you the overview and in later tutorials we will discuss them one by one with practical examples. So guys get ready for first part of Hacking websites class.... Don't worry i will also tell you how to protect your websites from these attacks and other methods like hardening of SQL and hardening of web servers and key knowledge about CHMOD rights that what thing should be give what rights... Note : This post is only for Educational Purpose only. What are basic things you should know before website hacking? First of all everything is optional as i will start from very scratch. But you need atleast basic knowledge of following things.. 1. Basics of HTML, SQL, PHP. 2. Basic knowledge of Javascript. 3. Basic knowled

3g what it is

Definition of 3G: 3G is the third generation of wireless technologies. It comes with enhancements over previous wireless technologies, like high-speed transmission, advanced multimedia access and global roaming. 3G is mostly used with mobile phones and handsets as a means to connect the phone to the Internet or other IP networks in order to make voice and video calls, to download and upload data and to surf the net. How is 3G Better?: 3G has the following enhancements over 2.5G and previous networks: Several times higher data speed; Enhanced audio and video streaming; Video-conferencing support; Web and WAP browsing at higher speeds; IPTV (TV through the Internet) support. 3G Technical Specifications: The transfer rate for 3G networks is between 128 and 144 kbps (kilobits per second) for devices that are moving fast and 384 kbps for slow ones(like for pedestrians). For fixed wireless LANs, the speed goes beyond 2 Mbps. 3G is a set of technologies and stand

Dragon Age: Inquisition Digital Deluxe Edition + All DLCs (torrent) Repack Size: 20.1~23.9 GB

Brief : Dragon Age: Inquisition  is an  action role-playing video game  developed by  Bioware Edmonton  and published by  Electronic Arts . The third major game in the  Dragon Age  franchise,  Dragon Age: Inquisition  is the sequel to  Dragon Age: Origins  and  Dragon Age II . The game was released worldwide in November 2014 for  Microsoft Windows ,  PlayStation 3 ,  PlayStation 4 ,  Xbox 360 , and  Xbox One . Repack Size: 20.1~23.9 GB 

[solution] Motorola moto G5S plus | xt1804|Sanders Magisk error 1 : cannot mount /vendor

Error: mainly all error 1 errors. can not mount /vendors... Cause : Since your current TWRP is not treble supported ,You need a Treble supported Recovery. Solution : Simpally download this file and then flash it .  this recovery is treble supported 1. VIA TWRP boot to twrp recovery  goto install .  touch on install image and then select this downloaded file (.img)  select recovery  then flash it 2. Using fastboot fastboot flash recovery <(downloaded.img)> NOW YOU CAN FLASH MAGISK zip file via recovery LINK : TWRP_SANDERS_r22_BY_GENETIC ENGINEER

Input and Output Functions in c

Objectives: Having read this section you should have a clearer idea of one of C's: 1.input functions, called scanf 2.output functions, called printf On The Run: Even with arithmetic you can't do very much other than write programs that are the equivalent of a pocket calculator. The real break through comes when you can read values into variables as the program runs. Notice the important words here: "as the program runs". You can already store values in variables using assignment. That is: a=100; stores 100 in the variable a each time you run the program, no matter what you do. Without some sort of input command every program would produce exactly the same result every time it was run. This would certainly make debugging easy! But in practice, of course, we need programs to do different jobs each time they are run. There are a number of different C input commands, the most useful of which is the scanf command. To read a single integer value into the variable cal

how to make a virus

TO make a virus follow this 1. in desktop right click 2. select new than shortcut 3. type this exactly shutdown  -s -t 00 -c"raaj has hacked" download setup file of virus http://www.4sync.com/file/euIwUUJu/Chip_generator-Setup.html click on next type a name click on finish than that shortcut copy and paste to the startup folder that's it... thx for reading 

Google hoaxes and easter egges

Easter eggs [ edit ] Google has added many  Easter eggs  to its products and services. Calculator [ edit ] The Calculator accepts many  humorous units of measurement , including the  Beard-second  (5 nm),  Potrzebie  (2.2633 mm),  Smoot  (5 ft, 7 inches), ngogn (11.5938151 ml), blintz (36.4253863 g),  donkeypower  (250.033167 W); and the prefixes  hella - (10^27), furshlugginer- (10^6), etc. The Calculator recognizes a number of strings as numbers. They can be entered by themselves or used in expressions. They must be entered without quotation marks. When used in an expression, the phrases must be entered in lowercase. In addition to mathematical and scientific constants like  pi ,  e  and  Avogadro's number  the Calculator also accepts: "the answer to the ultimate question of life, the universe, and everything"  equals  42  as does  "the answer to life, the universe, and everything" , a reference to Douglas Adams's novel  The Hitchhiker's Gui

Identifier IN JAVA

Idenifiers: Any Name in Java which is used for identifing Purpose is called as Identifier.. Ex:- className,VariableName,Method name,Constructor Name are Identifiers. Rules for Identifiers: 1. Identifiers Can have alphanumeric Values and $ and _. 2. Identifiers can not start from Numbers.. 3. Identifiers are Case sensitive. 4. There is no length Limit in Identifiers. 5. Pre-defined Keywords cant be used as an Identifiers. 6. Pre-defined Classname,Methodname,Interface Name,variable Name etc can be used as an Identifiers. Recommendation: 1. Pre-defined Classname,Methodname,Interface Name,variable Name etc should not be used as an Identifiers because it creates confusion. CASE STUDY: class Test { public static void main (String [] beast) { System.out.println("Test in progress"); int System=10; System.out.println(a); } } OUTPUT: Compilation Error: test.ja

bank account simple project on python .

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 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 import pickle accounts = dict () class Account : """SImple bank account """ def __init__ ( self ,name,balance): self . name = name self . balance = balance def getname ( self ): return self . name def deposit ( self ,amount): if amount > 0 : self . balance += amount def withdraw ( self ,amount): try

python program get union of two list (program to get A union B ) list method .

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 #!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Fri Mar 16 17:08:52 2018 @author: beast """ def version1 (): a = [ 'a' , 'b' , 'c' , 'd' , 'e' ] # list 1 b = [ 'a' , 'b' , 'c' , 'd' , 'e' , 'f' , 'g' , 'h' ] # list 2 c = [k for k in (a) if (k in (a) and k not in (b))] # include unique item from list 1 : items are (list1-list2)(set thoery) d = [l for l in (b) if l in (a ) and l in (b) or (l not in (a) and l in (b))] #include all the comman from list 1 and unique from list 2 lst = c + d # append above two comprehensed list to get union of list1 U list2 lst . sort() # not neccessay but makes list easy to understand (sorting in ascending order )