Showing posts with label Programming. Show all posts
Showing posts with label Programming. Show all posts

Variables Scope in PHP : Explained in easy language

Variables Scope in PHP

There are three types of variable scopes in PHP .  They are as follows:

1)      Local

2)      Global

3)      Static

Local Scope : When a variable declared inside a function (has a local scope ) and it can only be accessed within that function, the variable is called as local scope variable .

E.g.

<?php

function localvar()

{

$x=6; //local scope variable

echo "Variable x inside function is : $x";

}

localvar();

echo "Variable x outside function is : $x";//generate an error like undefined variable

?>

 

Output:  

Variable x inside function is : 6

Notice: Undefined variable: x

Variable x inside function is :

 

Global Scope : When a variable declared outside a function (has a global scope) and it can only be accessed outside a function, the variable is called as global scope variable .

E.g.

 <?php

$x=10; //global scope

function globalvar()

{

echo "Variable x inside function is : $x";//generate an error like undefined variable

}

globalvar();

echo "Variable x outside function is : $x";

?>

Output:

Notice: Undefined variable x

Variable x inside function is :

Variable x outside function is : 10

Global Keyword : By using global keyword we can access a global variable within a function. Just add or write global keyword before the variables inside the function. As follows,

e.g.

<?php

$x=10; //global scope

function globalvar()

{

            global $x;//By using global keyword

echo "Variable x inside function is : $x<br>";

}

globalvar();

echo "Variable x outside function is : $x";

?>

Output :

Variable x inside function is : 10

Variable x outside function is : 10

 

Static Scope : When a function is executed , all of its variables are deleted. However we want a local variable not to be deleted. We need it for further job. Use the static keyword when you first declared the variable . Then each time the function is called , the variable will still have the information it contained from the last time the function called.

e.g.

<?php

function scopevar (){

            static $x=11;

            echo $x;

            $x++;

}

scopevar ();

echo "<br>";

scopevar();

echo "<br>";

scopevar ();

?>

Output :

11

12

13

     

              In that way we learn variables scope in short .

Note: Read this blog regularly for important concepts and interview questions.

This blog is useful for IT students, IT freshers, BCA/MCA freshers. This blog contains Resume Tips, interview questions with answers.

PHP program to check whether the given number is palindrome or not

This PHP program is very useful for IT freshers.

Most of the IT companies ask this program in technical interview.




PHP program to check whether the given number is palindrome or not.

<?php
// PHP program to check whether the given number is palindrome or not
$n=123;
$rev=0;
$n1=$n;
while((int)$n > 0){
$rem = $n % 10;
$rev = ($rev*10) + $rem;
$n = (int)$n / 10;
}
echo "Reverse of $n1 = ".$rev."<br/>";
if($n1 == $rev){
echo "$n1 is palindrom number";
}else{
echo "$n1 is not palindrom number";
}
?>

This blog is very useful for IT Freshers.
Use right side menus to read useful posts like Resume Tips, Interview questions, Jobs, Programming, etc.

Other important Posts:
How to find PHP version through command prompt in windows? 

Important PHP string functions


PHP program to check whether the given number is prime or not

This post is very important for IT Students and IT freshers.

The most important program asked in various interviews or technical tests:
Write a PHP program to check whether the given number is prime or not.




What is Prime number: the number which is divisible by 1 and itself only.


So, here is the Program to check whether the given number is prime or not.

<?php
// What is Prime number: the number which is divisible by 1 and itself only.
$n=6; // The number which we want to check if it is PRIME or NOT PRIME
$prime=true;
for($i=2;$i<$n;$i++){
if($n%$i == 0){
$prime = false; // If Number is divisible by the $i iteration, it is not prime
break;
}
}
if($prime){
echo "PRIME";
}else{
echo "NOT PRIME";
}

?>

Output:
NOT PRIME

// when we assign value to n is 5 then output will be PRIME
--------------------------------------------------------------------------------------------




Other important posts for students of BCA/MCA/MCM/Msc/Bsc/MBA-IT/BE/BTech

Guidance for IT Students

Future of PHP Developer

PHP: Past, Today and Future

This blog is very helpful for IT Students and IT Freshers.


PHP Developer Salary: How much does a PHP Developer make?





In India, It's depends upon company, location and your skills. An average starting annual salary of php developer is near to 90,0000 INR that goes up to 4.50 lakhs in a three years of time.

In India, starts from as low as 8k/month to as high as 1.5L/month. Although low paying sections are more occupied.

As a programmer you need to have a very good understanding of how development technologies works in general and how are they co-related.

Summary:
For Freshers its 8-12K.
After 1 year - 16K
After 2 year - 22K
After 3 Year - 30K
After 4 Year - 36K
After 5 Year - Upto 45K
-60K


PHP Developer Salary depends on experience, logic, ideas, innovation, contacts, business development etc etc stuff. 

Learn and earn. 




Why this" i" in every for loop (outer) and "j" in inner for loop?


One idea is that i is used for "index".

Answer1:
One major factor for such practice could be the resources available. Majority of programming books and online resources follow the same notation. They tend to use 'i' for outer and 'j' for the inner loop, irrespective of the programming language used. While starting to program, you can easily get used to what you see regularly.

Why is it 'i' and not 'a' or 'b'? Well, loops are normally used while iterating an array. The elements are accessed through their index. Instead of using the name 'index', I can simply use 'i'. What about 'j'? I really don't know. Let me guess. The letter 'j' follows 'i'.

Answer2:

i and j have been used in maths long before it was used in programming. It is also used in papers that predate higher level languages (remember seeing stuff like  "Xi,j").

Well when fortran was designed they apparently followed the same trend, that they assigned alphabets starting with i to n to integers and and all other would default to real number(floating point).

Most people seem to have seen little reason to change that. It's widely known and understood, and quite succinct. Every once in a while you see something written by some psychotic who thinks there's a real advantage to something like:

for (int outer_index_variable=0; outer_index_variable < 10; outer_index_variable++)  
 for (int inner_index_variable=0; inner_index_variable<10;        inner_index_variable++)   
      x[outer_index_variable][inner_index_variable] = 0;

Thankfully this is pretty rare though, and most style guides now point out that while long, descriptive variable names can be useful, you don't always need them, especially for something like this where the variable's scope is only a line or two of code.


Programming : C and C++

Programming : C and C++





About C language:
The C is a general-purpose, procedural, imperative computer programming language developed in 1972 by Dennis M. Ritchie at the Bell Telephone Laboratories to develop the UNIX operating system.

The C is the most widely used computer language, it keeps fluctuating at number one scale of popularity along with Java programming language, which is also equally popular and most widely used among modern software programmers.

Why to use C?

C was initially used for system development work, in particular the programs that make-up the operating system. C was adopted as a system development language because it produces code that runs nearly as fast as code written in assembly language.
Some examples of the use of C might be:
Operating Systems
Language Compilers
Assemblers
Text Editors
Print Spoolers
Network Drivers
Modern Programs
Databases
Language Interpreters
Utilities


About C++ :
C++ is a middle-level programming language developed by Bjarne Stroustrup starting in 1979 at Bell Labs. C++ runs on a variety of platforms, such as Windows, Mac OS, and the various versions of UNIX.

C++ is a statically typed, compiled, general-purpose, case-sensitive, free-form programming language that supports procedural, object-oriented, and generic programming.

C++ is regarded as a middle-level language, as it comprises a combination of both high-level and low-level language features.

C++ was developed by Bjarne Stroustrup starting in 1979 at Bell Labs in Murray Hill, New Jersey, as an enhancement to the C language and originally named C with Classes but later it was renamed C++ in 1983.

C++ is a superset of C, and that virtually any legal C program is a legal C++ program.


Object-Oriented Programming:
C++ fully supports object-oriented programming, including the four pillars of object-oriented development:

Encapsulation
Data hiding
Inheritance
Polymorphism

what is C++ used for?





C++ is a powerful general-purpose programming language. It can be used to create small programs or large applications.
It can be used to make CGI scripts or console-only DOS programs. C++ allows you to create programs to do almost anything you need to do.


What do I need to start programming in C or C++?

In order to make usable programs in C or C++, you will need a compiler. A compiler converts source code - the actual instructions typed by the programmer - into an executable file. Numerous compilers are available for C and C++.

Do I need to know C to learn C++?

No. C++ is a superset of C; (almost) anything you can do in C, you can do in C++. If you already know C, you will easily adapt to the object-oriented features of C++. If you don't know C, you will have to learn the syntax of C-style languages while learning C++, but you shouldn't have any conceptual difficulties.

Enjoy Programming.

Game Development: using C++ or other

Game Development: using C++ or other

C++ is one of the best and most used programming language in Game Development, Animation tools and technologies. If you search google you will get a lot of results on this.






C++ game development is not odd. There are a lot of online resources available and also books are available. I will provide you with some links:
http://www.gametutorials.com/tutorials/cpp-tutorials/

Wanting to "Learn game development" is very, very vague.
If you want to develop your own, small games, for fun, while learning how to structure the application, go with python.
If you want to learn more hard-core graphics programming, or gain experience towards working in the industry, I would have to say go with c++.
I think the answer depends very much on your current skill set and goals. Note that I'm certainly no expert in the field.

C++ is the language used to actually write the game, at least for the graphically-intensive complex games like World of Warcraft. Languages like Python are often used for scripting behaviors within the game.
If you want to be hired in the industry, get good at C++. Real good.

As a game developer, what are your most used concepts in C++?
Answer:Pointers
STL
Implementation of OOPS, Data structure, Design patterns via c++


The Best site to refer: http://www.cppgameprogramming.com/






Visit Facebook Page and LIKE: Technology Park  for daily updates.

Write C++ program for Fibonacci series: 0 1 1 2 3 5 8 13

Write C++ program for Fibonacci series: 0 1 1 2 3 5 8 13




Program:

#include<iostream.h>
#include<conio.h>
void main()
{

clrscr();
int f1,f2,f3;
int n=8;
f1=0;
f2=1;
cout<<f1<<" "<<f2;
for(int i=3;i<=n;i++;)
{
f3=f1+f2;
cout<<f3<<" ";
f1=f2;
f2=f3;
}

getch();

}




Write a c++ program to find sum and average of two numbers.

Write a c++ program to find sum  and average of two numbers.
This question always asked in Technical Interview.




#include <iostream.h>
#include <conio.h>

void main()
{
clrscr();

int x,y,sum;
float average;
cout << "Enter 2 integers : " << endl;
cin>>x>>y;
sum=x+y;
average=sum/2;
cout << "sum="<< sum << "." << endl;
cout << "average=" << average << "." << endl;

getch();

}


SAMPLE INPUT:
Enter 2 integers :
8 6

SAMPLE OUTPUT:
sum=14.
average=7.






Write a C++ program to print a pattern :

Write a C++ program to print a pattern :
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5

This question always asked in Technical Interview.






Program:


#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int i,j;

for(i=1;i<=5;i++)
{
for(j=1;j<=i;j++)
{

cout<<j<<" ";
}
cout<<"\n";
}
getch();
}


output:

1
1 2
1 2 3
1 2 3 4
1 2 3 4 5




What should I do, after 12th?






What should I do, after 12th?

Everyone is confused at the level of leaving high school life. Specially if the students are from rural area.
If you have this question, at this stage, You are on the right way.
And this is not abnormal, its common. But it should not happen. Everyone should analyse yourself whats your interest. What exactly you want to become?

If you loves writing, go for it.
If you like sports, join some good college or institute which is special for sports.

First thing, everyone wants to earn money. Ant thing is that, there is a big misunderstanding, that IT field gives more money. Hey, the days are gone. Now IT industry hiring the talent only, not the degree holders or toppers, or who has 90% or more.
Coming to the point what to do after 12th?
Decide on your own.
You may say, then why you are writing this article, right?
Yes, this is the article just to remind you, you have freedom to choose your career, life.
You can earn money (if money is important to you), in any field.
I am not going to include all the things that you should do after 12th.
But some of them are:
Animation
Arts
Sports
Journalism
Politics
Computer Science
Health science
Management
Business Administration
Hotel Management
Language Specialization (foreign languages)
Marketing
Medical
Engineering
Social Working
Artificial Intelligence

Important Note:
This is the blog especially for IT people. Many of the people asking me to write about “what to do after 12th  ?”. The purpose of question is mostly confusion of choosing BCA/BBA or another.
See, Now a day’s millions of candidates passing degree of IT, each year, and this number is increasing. The number of candidates required by IT Industry is around 2, 00,000 only.
If you are good at programming, logic, and you are ready to learn everything related to IT/Software, go for BCA.
Otherwise not.
And if you have already been taken admission for BCA, then learn Programming, improve logic, learn everything related to IT/Software, no option.
The crowd of IT candidates, is going to increase in marketing.
So, again saying, decide on your own. Ask yourself what exactly you are interested in!
Do whatever you want nothing is meaningless.
You can earn money, by your talent, knowledge, skills, not by Degree.
There are always exists some courses, related to your interests!

If you can learn, obviously you can earn.

(Article submitted by: Vanesh Mali)
copyright@Vanesh Mali

Notice: 





We will post the next article on “Scope for BCA”. 
Stay connected.
Visit the Blog TECHNOLOGY PARK daily.
For Daily updates, LIKE our FACEBOOK page: Technology Park.
We would love to hear from you.
Contact us: hellotechnologypark@gmail.com






Pointers in C++ is a useless topic. "Wrong"





Question from my mail Box:
How can I prove my friend, who says "Pointers in C++ is a useless topic.", wrong?

I replied:
Ask him if you can visit his home, he will agree. Tell him to bring his home to your place. He will ask you if you are drunk. Then ask him his address, he will give you. Now you can visit his home.

Giving address to your friends is easier than copying your home everywhere. That's what pointers do.


In other way you can prove as:




Though pointers are most powerful in C but they are not useless in C++. C++ is an extension of C with addition of OOP's features. What makes C++ a strong language for programming is that it allows you to use OOP's features and access them using pointers.

In C++ you can pass objects to a function using a pointer, you can access an object and also call a method of an object just using pointers. Interfaces in C++ are generally access through pointers.

(Article submitted by : Vanesh Mali)

you can contact us at: hellotechnologypark@gmail.com

How to Make a Link Open in a New Tab Using HTML

The Question asked in Technical Interview for BCA/MCA Freshers:

How to Make a Link Open in a New Tab Using HTML

The basic code for any link is:

< a href=”somepage.html”> Go To somepage</a >

To Open specified link in new tab, your code should look something like this:

< a href=”somepage.html” target=”_blank”> Go To somepage</a >

By setting the target attribute as _blank, we are able to open a link in new tab.

Note: For More Interview Questions and Resume Tips visit this website daily.

We will upload most important interview questions, technical interview questions for BCA and MCA freshers.

This blog is for:
BCA MCA Freshers, Software Companies, IT Students, Training Institutes, Colleges, Teachers, Learners, Leaders, Earners,...





: for more details or any query email us: hellotechnologypark@gmail.com 



C Programming: Objective Questions and answers

These are the questions asked in various companies, for freshers (BCA, MCA).
If you are going for technical interview of IT Company then you must be prepare for these questions.
Here are List of Questions with answers.




1. In which numbering system can the binary number 1011011111000101 be easily converted to?

A. Decimal system
B. Hexadecimal system
C. Octal system
D. No need to convert

Answer & Explanation
Answer: Option B

Explanation:

Hexadecimal system is better, because each 4-digit binary represents one Hexadecimal digit.


2.If the two strings are identical, then strcmp() function returns

A. -1
B. 1
C. 0
D. Yes

Answer & Explanation
Answer: Option C

Explanation:

Declaration: strcmp(const char *s1, const char*s2);

The strcmp return an int value that is

if s1 < s2 returns a value < 0

if s1 == s2 returns 0

if s1 > s2 returns a value > 0


3. How will you print \n on the screen?

A. printf("\n");
B. echo "\\n";
C. printf('\n');
D. printf("\\n");

Answer & Explanation
Answer: Option D

Explanation:

The statement printf("\\n"); prints '\n' on the screen.

4. Which header file should be included to use functions like malloc() and calloc()?

A. memory.h
B. stdlib.h
C. string.h
D. dos.h
Answer & Explanation
Answer: Option B


5. What function should be used to free the memory allocated by calloc() ?

A. dealloc();
B. malloc(variable_name, 0)
C. free();
D. memalloc(variable_name, 0)

Answer: Option C


How to submit form using Javascript?




If HTML form have the attributes method="post" and action="someprocess.php", and in the form if there is button like,
<input type="submit" value="submit"> , then form will get submitted on that button click.

But if we want to submit the form on any link i.e <a>  tag or any event other than submit button, then we have to use javascript.

How ?
 See,
Here is the code to submit a form when a hyperlink is clicked:

<form name="myform" action="process.php">
Text Field: <input type='text' name='text1' />
<a href="javascript: submitform()">Search</a>
</form>

<script type="text/javascript">
function submitform()
{
  document.myform.submit();
}
</script>


Javascript submit is same as HTML submit.
You can submit form on events like: onChange, onClick,....etc.

I think its enough to understand the concept.

I would like to hear from you...!!!


C# Interview Questions



General Questions:
  1. Does C# support multiple-inheritance?
    No.
     
  2. Who is a protected class-level variable available to?
    It is available to any sub-class (a class inheriting this class).
     
  3. Are private class-level variables inherited?
    Yes, but they are not accessible.  Although they are not visible or accessible via the class interface, they are inherited.
     
  4. Describe the accessibility modifier “protected internal”.
    It is available to classes that are within the same assembly and derived from the specified base class.
     
  5. What’s the top .NET class that everything is derived from?
    System.Object.
     
  6. What does the term immutable mean?
    The data value may not be changed.  Note: The variable value may be changed, but the original immutable data value was discarded and a new data value was created in memory.
     
  7. What’s the difference between System.String and System.Text.StringBuilder classes?
    System.String is immutable.  System.StringBuilder was designed with the purpose of having a mutable string where a variety of operations can be performed.
     
  8. What’s the advantage of using System.Text.StringBuilder over System.String?
    StringBuilder is more efficient in cases where there is a large amount of string manipulation.  Strings are immutable, so each time a string is changed, a new instance in memory is created.
     
  9. Can you store multiple data types in System.Array?
    No.
     
  10. What’s the difference between the System.Array.CopyTo() and System.Array.Clone()?
    The Clone() method returns a new array (a shallow copy) object containing all the elements in the original array.  The CopyTo() method copies the elements into another existing array.  Both perform a shallow copy.  A shallow copy means the contents (each array element) contains references to the same object as the elements in the original array.  A deep copy (which neither of these methods performs) would create a new instance of each element's object, resulting in a different, yet identacle object.
     
  11. How can you sort the elements of the array in descending order?
    By calling Sort() and then Reverse() methods.
     
  12. What’s the .NET collection class that allows an element to be accessed using a unique key?
    HashTable.
     
  13. What class is underneath the SortedList class?
    A sorted HashTable.
     
  14. Will the finally block get executed if an exception has not occurred?­
    Yes.
     
  15. What’s the C# syntax to catch any possible exception?
    A catch block that catches the exception of type System.Exception.  You can also omit the parameter data type in this case and just write catch {}.
     

What's the difference between a programming language, a scripting language?



What's the difference between a programming language, a scripting language?




The main difference between a "programming language" (C, C++ etc.) and a "scripting language" (ASP, JSP, JavaScript, VBScript) is that code written in a programming language needs to be compiled before it is run. Once it is compiled, it can be run any number of times.

Scripting languages, on the other hand, are interpreted at run-time. This means that every time you want to run the program, a separate program needs to read the code, interpret it, and then follow the instructions in the code. Compiled code has already been interpreted into machine language, so it is will typically execute faster because the conversion into machine language has already been done.

--Vanesh.